Error Handling¶
Result codes¶
Every call across the DLL boundary, in both directions, returns an integer result code plus a JSON body.
| Code | Name | Meaning |
|---|---|---|
0 |
OK |
Success. The body is the response object |
1 |
ERROR |
Failure. The body is {"error": {"code", "message"}} |
2 |
NOT_SUPPORTED |
The callee does not implement this method. Empty body |
The SDK returns NOT_SUPPORTED when your override returns null, or when the host calls a method your SDK version does not know. The host treats it as "no answer" and uses its default: BeforeFileOpen and BeforeFileClose fail open, GetMenuItemState falls back to requiresOpenProject, and other calls do nothing. Two exceptions: GetInfo and Initialize must return OK, or the plugin fails to load.
The host checks GetInfo.capabilities before calling an optional plugin method. If the capability is absent, the call is skipped entirely. Lifecycle and menu methods are not capability-gated. See Architecture.
Reporting errors from the plugin¶
Throw PluginException with a machine-readable code and a message for the user:
throw new PluginException("NOT_FOUND", "Article code not found in ERP.");
throw new PluginException("CONNECTION_FAILED", "Could not reach ERP server.");
The SDK serializes it as:
Any other exception becomes INTERNAL_ERROR with the exception message. An exception that escapes the SDK entirely (for example, no plugin registered) becomes FATAL. An Initialize request missing a required field is rejected by the SDK with VALIDATION_ERROR before your code runs.
Suggested plugin error codes¶
| Code | When to use |
|---|---|
NOT_FOUND |
Item does not exist in the external system |
CONNECTION_FAILED |
Database, ERP, or PDM unreachable |
AUTHENTICATION_FAILED |
Bad or expired credentials |
ACCESS_DENIED |
Permission denied |
CONFLICT |
File locked by another user |
VALIDATION_ERROR |
Invalid request data |
TIMEOUT |
External system timeout |
Host API errors¶
When a Host.* call fails, the SDK throws HostApiException with the code and message from the host.
Host.ShowMessage and Host.SetStatusBar raise no method-specific errors. Host.SaveFile reports a cancelled or failed save as saved: false, not as an error.
| Code | Host.* methods | When |
|---|---|---|
NO_PROJECT_OPEN |
All project-scoped reads, writes, and exports | No matching open document. With projectPath omitted, HydroSym uses the active window, which must be a schematic |
INVALID_ARGUMENT |
OpenProject (empty filePath); NewProject, SaveProjectAs (empty path or extension other than .hdf / .mnf); HydroSym ExportDrawing, ExportBom (format other than "pdf") |
Bad argument. Checked before the project is resolved |
FILE_NOT_FOUND |
OpenProject |
Path does not exist on disk |
NO_UI |
HydroSym OpenProject, NewProject; HydroMan NewProject |
HydroSym command-line mode. SaveProjectAs and SaveFile work without a GUI |
OPEN_FAILED |
OpenProject |
File exists but no schematic or manifold window resulted (wrong file type, load failure, or your own BeforeFileOpen vetoed it) |
FILE_EXISTS |
NewProject, SaveProjectAs |
Destination already exists |
CREATE_FAILED |
NewProject |
Host could not create or verify the new file |
READ_ONLY |
SaveProjectAs, SaveFile |
Document was opened read-only |
SAVE_FAILED |
SaveProjectAs |
Write or post-save verification failed |
EXPORT_FAILED |
HydroSym ExportDrawing, ExportBom; HydroMan ExportPdf |
Export produced no file, for example a manifold without a production layout |
NO_OUTPUT_PATH |
HydroMan ExportPdf |
filePath omitted and the manifold has never been saved |
HOST_NOT_INITIALIZED |
Any | The host had no handler registered. Does not occur during a normal plugin session (GetInfo through Finalize) |
HOST_ERROR |
Any | Unexpected exception inside the host |
HOST_NOT_AVAILABLE |
Any (raised by the SDK) | The host returned NOT_SUPPORTED, for example for a method this host version does not implement |
HOST_RESPONSE_INVALID |
Any (raised by the SDK) | The host returned OK but the JSON could not be deserialized |
Handle HostApiException where you can recover, and let it propagate otherwise. An unhandled one inside OnMenuAction reaches the user as Plugin error: [OnMenuAction] <message>.