siyuan-note/siyuan · error

invalid plugin service HTTP status

Error message

invalid plugin service HTTP status

What it means

validatePluginServiceHTTPResponse first sanity-checks the status code as a valid HTTP code (100-999) before applying body rules. This error means a status outside 100-999 (0, negative, or >999) was passed while validating a plugin-service HTTP response, so the value cannot be an HTTP status at all.

Solutions

  1. Initialize the status to a valid HTTP code (e.g. 200) before validation
  2. Check where the status is computed; replace custom codes with standard HTTP status codes
  3. Guard with `if status < 100 || status > 999 { status = http.StatusInternalServerError }` before calling validation

Example fix

// before
status := 0
bundle.ValidateHTTPResponse(endpoint, status, ct, payload)
// after
status := http.StatusOK
bundle.ValidateHTTPResponse(endpoint, status, ct, payload)
Defensive patterns

Strategy: validation

Validate before calling

func validHTTPStatus(status int) bool {
	return status >= 100 && status <= 999
}
if !validHTTPStatus(status) {
	status = http.StatusInternalServerError
}

Prevention

When it happens

Trigger: Calling Bundle.ValidateHTTPResponse for a plugin-service endpoint with status 0 (unset), a negative value, or a number above 999, typically when the status variable was never assigned or carries a custom non-HTTP code.

Common situations: Forgetting to set the response status so the zero value 0 is validated; passing an application-specific error code instead of an HTTP status; integer overflow or sign errors when computing the status.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at kernel/apicontract/plugin_service_protocol.go:170

	case PluginServiceRedirect:
		if status != 201 && (status < 300 || status > 308) {
			return fmt.Errorf("invalid plugin redirect status")
		}
	case PluginServiceWebSocket:
		if status != 101 && status != 400 && status != 500 {
			return fmt.Errorf("invalid plugin WebSocket status")
		}
	case PluginServiceSSE:
		if status != 200 && status != 500 {
			return fmt.Errorf("invalid plugin SSE status")
		}
	}
	return nil
}

func (b *Bundle) validatePluginServiceHTTPResponse(endpoint EndpointSchema, status int, contentType string, payload []byte) error {
	if status < 100 || status > 999 {
		return fmt.Errorf("invalid plugin service HTTP status")
	}
	if endpoint.Method == "HEAD" || status < 200 || status == 204 || status == 304 {
		if len(payload) > 0 {
			return fmt.Errorf("plugin service response forbids a body")
		}
		return nil
	}
	// 原始文件、代理及插件自选媒体允许任意字节,具体分支由 ValidatePluginServiceResponse 校验。
	return nil
}

func (b *Bundle) ValidatePluginServiceResponse(method, path string, mode PluginServiceMode, status int, contentType string, payload []byte) error {
	var found bool
	for _, endpoint := range b.Endpoints {
		if endpoint.Method == method && endpoint.Path == path && endpoint.PluginService != nil {
			found = true
			break
		}

View on GitHub (pinned to 9f775e8a12)