siyuan-note/siyuan · error

Plugin returned invalid input

Error message

Plugin ${pluginLabel} returned invalid input: ${validationError}

What it means

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.

Solutions

  1. Fix the plugin so decision.input conforms to the expected asset-upload input schema (all required fields present and correctly typed)
  2. Run validateAssetUploadInput inside the plugin before returning the decision to pre-validate its own input
  3. Log the validationError string in the plugin to see exactly which field failed and correct it
  4. Update the plugin against the current plugin API declarations in petal/plugin-sample

Example fix

// before (in plugin)
return {action: "replace", input: {data: fileData}}; // missing required fields
// after
const input = {data: fileData, name: fileName, type: mimeType};
if (validateAssetUploadInput(input)) return {action: "cancel"};
return {action: "replace", input};
Defensive patterns

Strategy: validation

Validate before calling

const err = validateAssetUploadInput(decision.input);
if (err) {
  console.warn("Replacement input invalid:", err);
  return {action: "cancel"};
}

Type guard

const hasValidUploadInput = (input: unknown): boolean =>
  validateAssetUploadInput(input) === null;

Try / catch

try {
  await prepareAssetUpload(...);
} catch (e) {
  if (String(e.message).includes("returned invalid input")) {
    showMessage(e.message);
    cancelUpload();
  } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/1fae1a43b0c24836. Report an issue: GitHub.

Appendix: source

Thrown at app/src/protyle/upload/pluginEvent.ts:441

            discardResponse();
            return fail(responseError);
        }
        if (emitResult.hasAsyncListener && !responseClaimed) {
            return fail(new Error(`Plugin ${pluginLabel} must call respondWith synchronously before awaiting`));
        }
        if (!response) {
            return processPlugin(index + 1);
        }
        return waitForDecision(response, task, pluginLabel, timeout).then(decision => {
            if (decision?.action === "cancel") {
                return cancel();
            }
            if (decision?.action !== "replace") {
                throw new Error(`Plugin ${pluginLabel} returned an invalid action`);
            }
            const validationError = validateAssetUploadInput(decision.input);
            if (validationError) {
                throw new Error(`Plugin ${pluginLabel} returned invalid input: ${validationError}`);
            }
            const targetValidationError = validateTargetInput(decision.input, context);
            if (targetValidationError) {
                throw new Error(`Plugin ${pluginLabel} returned invalid input: ${targetValidationError}`);
            }
            task.input = cloneInput(decision.input);
            return processPlugin(index + 1);
        }).catch(error => error instanceof AssetUploadCanceledError ? cancel(error.message) : fail(error));
    };
    return processPlugin(0);
};

View on GitHub (pinned to 9f775e8a12)