{"record":{"id":"1fae1a43b0c24836","repo":"siyuan-note/siyuan","slug":"plugin-pluginlabel-returned-invalid-input-va","errorCode":null,"errorMessage":"Plugin ${pluginLabel} returned invalid input: ${validationError}","messagePattern":"Plugin (.+?) returned invalid input: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/protyle/upload/pluginEvent.ts","lineNumber":441,"sourceCode":"            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":423,"sourceCodeEnd":453,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/app/src/protyle/upload/pluginEvent.ts#L423-L453","documentation":"After a plugin chooses action \"replace\" during asset upload, its replacement input is checked with validateAssetUploadInput. If validation fails, the code throws 'Plugin ${pluginLabel} returned invalid input: ${validationError}', meaning the plugin supplied malformed or incomplete upload input data.","triggerScenarios":"A plugin resolves the replace decision with an input object that fails validateAssetUploadInput — missing/empty fields, wrong types, or an invalid data/path value for the replacement asset.","commonSituations":"Plugin builds the replacement input from user-supplied data without validating; plugin API version mismatch causing a changed input schema; plugin returns input constructed for a different upload type.","solutions":["Fix the plugin so decision.input conforms to the expected asset-upload input schema (all required fields present and correctly typed)","Run validateAssetUploadInput inside the plugin before returning the decision to pre-validate its own input","Log the validationError string in the plugin to see exactly which field failed and correct it","Update the plugin against the current plugin API declarations in petal/plugin-sample"],"exampleFix":"// before (in plugin)\nreturn {action: \"replace\", input: {data: fileData}}; // missing required fields\n// after\nconst input = {data: fileData, name: fileName, type: mimeType};\nif (validateAssetUploadInput(input)) return {action: \"cancel\"};\nreturn {action: \"replace\", input};","handlingStrategy":"validation","validationCode":"const err = validateAssetUploadInput(decision.input);\nif (err) {\n  console.warn(\"Replacement input invalid:\", err);\n  return {action: \"cancel\"};\n}","typeGuard":"const hasValidUploadInput = (input: unknown): boolean =>\n  validateAssetUploadInput(input) === null;","tryCatchPattern":"try {\n  await prepareAssetUpload(...);\n} catch (e) {\n  if (String(e.message).includes(\"returned invalid input\")) {\n    showMessage(e.message);\n    cancelUpload();\n  } else { throw e; }\n}","preventionTips":["Validate input with validateAssetUploadInput inside the plugin before returning it","Construct input from the context passed to the plugin rather than ad-hoc data","Keep plugin API declarations (petal) in sync","Log the validationError detail during plugin development"],"tags":["plugin","validation","upload"],"backgroundTag":"schema-validation-failed","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"}