package apiclient

// RawStage returns the server stage bytes exactly as received, with no trim.
// Identity validation (the Exec allowlist / canonical stage grammar) must run on
// the raw bytes so a spaced or malformed stage can never be silently trimmed
// into a valid one before projection.
func (e *APIError) RawStage() string {
	if e == nil {
		return ""
	}
	if e.StageName != "" {
		return e.StageName
	}
	if details, ok := e.Details.(map[string]any); ok {
		if stage, ok := details["stage"].(string); ok {
			return stage
		}
	}
	return ""
}
