{"record":{"id":"32836d20283c8de8","repo":"siyuan-note/siyuan","slug":"plugin-pluginlabel-returned-an-invalid-action","errorCode":null,"errorMessage":"Plugin ${pluginLabel} returned an invalid action","messagePattern":"Plugin (.+?) returned an invalid action","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/protyle/upload/pluginEvent.ts","lineNumber":437,"sourceCode":"            discardResponse();\n            return fail(new Error(`Plugin ${pluginLabel} must use respondWith to replace or cancel an asset upload`));\n        }\n        if (responseError) {\n            discardResponse();\n            return fail(responseError);\n        }\n        if (emitResult.hasAsyncListener && !responseClaimed) {\n            return fail(new Error(`Plugin ${pluginLabel} must call respondWith synchronously before awaiting`));\n        }\n        if (!response) {\n            return processPlugin(index + 1);\n        }\n        return waitForDecision(response, task, pluginLabel, timeout).then(decision => {\n            if (decision?.action === \"cancel\") {\n                return cancel();\n            }\n            if (decision?.action !== \"replace\") {\n                throw new Error(`Plugin ${pluginLabel} returned an invalid action`);\n            }\n            const validationError = validateAssetUploadInput(decision.input);\n            if (validationError) {\n                throw new Error(`Plugin ${pluginLabel} returned invalid input: ${validationError}`);\n            }\n            const targetValidationError = validateTargetInput(decision.input, context);\n            if (targetValidationError) {\n                throw new Error(`Plugin ${pluginLabel} returned invalid input: ${targetValidationError}`);\n            }\n            task.input = cloneInput(decision.input);\n            return processPlugin(index + 1);\n        }).catch(error => error instanceof AssetUploadCanceledError ? cancel(error.message) : fail(error));\n    };\n    return processPlugin(0);\n};\n","sourceCodeStart":419,"sourceCodeEnd":453,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/app/src/protyle/upload/pluginEvent.ts#L419-L453","documentation":"In processPlugin, after waiting for a plugin's decision on an asset-upload conflict, only actions \"cancel\" and \"replace\" are accepted. If the plugin resolves with any other (or an unrecognized) action value, the code throws 'Plugin ${pluginLabel} returned an invalid action'. This enforces the plugin-decision protocol for asset uploads.","triggerScenarios":"A plugin's event handler for the asset-upload decision resolves waitForDecision with an object whose action is neither \"cancel\" nor \"replace\" (e.g. \"skip\", \"overwrite\", typo, or undefined action with a non-null decision object).","commonSituations":"A plugin author returns a custom action name expecting it to be honored; a plugin version predates the current decision protocol; a bug where decision = {action: null} but decision itself is truthy.","solutions":["Fix the plugin to return only \"cancel\" or \"replace\" as the action value in its decision object","Return null/undefined from the plugin handler instead of an object when no decision is made (null decision bypasses both checks)","Update the plugin to the current siyuan plugin API version and check plugin-sample for the correct decision shape","Log the received decision object in the plugin to identify what action value it actually returns"],"exampleFix":"// before (in plugin)\nreturn {action: \"overwrite\", input};\n// after\nreturn {action: \"replace\", input};","handlingStrategy":"validation","validationCode":"function isValidDecision(d) {\n  return d === null || d === undefined ||\n    (typeof d === \"object\" && (d.action === \"cancel\" || d.action === \"replace\"));\n}","typeGuard":"type PluginDecision = {action: \"cancel\"} | {action: \"replace\", input: unknown} | null;\nconst isPluginDecision = (d: unknown): d is PluginDecision =>\n  d === null || (typeof d === \"object\" && d !== null &&\n  [\"cancel\", \"replace\"].includes((d as any).action));","tryCatchPattern":"processPlugin(...).catch(err => {\n  if (String(err.message).includes(\"returned an invalid action\")) {\n    console.error(\"Plugin decision protocol violated:\", err.message);\n    cancelUpload();\n  } else { throw err; }\n});","preventionTips":["Only return \"cancel\" or \"replace\" as action values from plugin handlers","Return null when no decision is needed","Test plugins against the current plugin API version","Type the decision return value in the plugin with the official petal types"],"tags":["plugin","upload","protocol"],"backgroundTag":"invalid-enum-value","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}