{"id":"8d1ecde6f82d4cd8","repo":"gofiber/fiber","slug":"value-not-found","errorCode":null,"errorMessage":"value not found","messagePattern":"value not found","errorType":"validation","errorClass":"ErrNotFound","httpStatus":null,"severity":"warning","filePath":"extractors/extractors.go","lineNumber":64,"sourceCode":"\n\t// SourceForm indicates the value is extracted from form data.\n\tSourceForm\n\n\t// SourceQuery indicates the value is extracted from URL query parameters.\n\tSourceQuery\n\n\t// SourceParam indicates the value is extracted from URL path parameters.\n\tSourceParam\n\n\t// SourceCookie indicates the value is extracted from cookies.\n\tSourceCookie\n\n\t// SourceCustom indicates the value is extracted using a custom extractor function.\n\tSourceCustom\n)\n\n// ErrNotFound is returned when the requested value is missing or empty.\nvar ErrNotFound = errors.New(\"value not found\")\n\n// ErrChainCycle is returned when a chain extractor recursively invokes itself.\nvar ErrChainCycle = errors.New(\"cyclic extractor chain\")\n\n// Extractor defines a value extraction method with metadata.\ntype Extractor struct {\n\tExtract    func(fiber.Ctx) (string, error)\n\tKey        string      // The parameter/header name used for extraction\n\tAuthScheme string      // The auth scheme used, e.g., \"Bearer\"\n\tChain      []Extractor // For chained extractors, stores all extractors in the chain\n\tSource     Source      // The type of source being extracted from\n}\n\n// Contains reports whether this extractor, or any extractor in its chain, matches pred.\n//\n// If pred is nil, Contains returns false.\nfunc (e Extractor) Contains(pred func(Extractor) bool) bool {\n\tif pred == nil {","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/extractors/extractors.go#L46-L82","documentation":"ErrNotFound ('value not found', extractors/extractors.go:64) is the shared sentinel returned by every extractor (FromHeader, FromCookie, FromQuery, FromForm, FromParam, FromAuthHeader, FromCustom) when the requested value is absent or empty. It is the normal 'no value here' signal used by Chain and by middleware (keyauth, csrf) to decide whether to try the next source or reject the request. It is not a fatal error; it is expected control flow.","triggerScenarios":"FromHeader(\"X-API-Key\").Extract(c) when the header is missing; FromCookie(\"session\").Extract(c) with no cookie; FromAuthHeader(\"Bearer\") when the Authorization header is absent or malformed; FromParam(\"id\") on a route that didn't define :id; Chain(...) where every source returns empty. Any extractor encountering an empty/missing value returns it.","commonSituations":"Auth middleware not finding a token in the configured source, clients sending tokens in a different location than configured, or route/query/cookie name typos. Normal first-request-before-login traffic also produces it.","solutions":["When using a single extractor, treat ErrNotFound as 'unauthenticated' and return 401, not a 500.","Use Chain() to fall back across header -> cookie -> query sources so a missing value in one is not fatal.","Verify the header/cookie/query/param name matches what the client actually sends (case-insensitive for headers)."],"exampleFix":"// before\ntok, err := extractors.FromHeader(\"X-API-Key\").Extract(c)\nif err != nil {\n    return fiber.NewError(fiber.StatusInternalServerError, err.Error())\n}\n\n// after\ntok, err := extractors.Chain(\n    extractors.FromHeader(\"X-API-Key\"),\n    extractors.FromCookie(\"api_key\"),\n).Extract(c)\nif errors.Is(err, extractors.ErrNotFound) {\n    return fiber.NewError(fiber.StatusUnauthorized, \"api key required\")\n}","handlingStrategy":"fallback","validationCode":"// Confirm a value is present before treating it as required.\nif v := c.Get(\"X-API-Key\"); v == \"\" {\n    return fiber.NewError(fiber.StatusUnauthorized, \"api key required\")\n}","typeGuard":null,"tryCatchPattern":"v, err := extractor.Extract(c)\nif err != nil {\n    if errors.Is(err, extractors.ErrNotFound) {\n        return fiber.NewError(fiber.StatusUnauthorized, \"credentials required\")\n    }\n    return err\n}","preventionTips":["Use Chain() to fall back across multiple extraction sources.","Treat ErrNotFound as expected control flow (401/redirect), not a server error.","Verify the source name matches what clients actually send."],"tags":["extractors","auth","middleware","fiber"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}