{"record":{"id":"238b70c83078c76a","repo":"googleapis/mcp-toolbox","slug":"error-getting-logger-from-context-in-extractlooker","errorCode":null,"errorMessage":"error getting logger from context in ExtractLookerFieldProperties: %v","messagePattern":"error getting logger from context in ExtractLookerFieldProperties: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/looker/lookercommon/lookercommon.go","lineNumber":50,"sourceCode":"\tFiltersFields    = \"fields(filters(name,type,label,label_short,description,synonyms,tags,hidden,suggestable,suggestions,suggest_dimension,suggest_explore))\"\n\tMeasuresFields   = \"fields(measures(name,type,label,label_short,description,synonyms,tags,hidden,suggestable,suggestions,suggest_dimension,suggest_explore))\"\n\tParametersFields = \"fields(parameters(name,type,label,label_short,description,synonyms,tags,hidden,suggestable,suggestions,suggest_dimension,suggest_explore))\"\n)\n\n// ExtractLookerFieldProperties extracts common properties from Looker field objects.\nfunc ExtractLookerFieldProperties(ctx context.Context, fields *[]v4.LookmlModelExploreField, showHiddenFields bool) ([]any, error) {\n\tdata := make([]any, 0)\n\n\t// Handle nil fields pointer\n\tif fields == nil {\n\t\treturn data, nil\n\t}\n\n\tlogger, err := util.LoggerFromContext(ctx)\n\tif err != nil {\n\t\t// This should ideally not happen if the context is properly set up.\n\t\t// Log and return an empty map or handle as appropriate for your error strategy.\n\t\treturn data, fmt.Errorf(\"error getting logger from context in ExtractLookerFieldProperties: %v\", err)\n\t}\n\n\tfor _, v := range *fields {\n\t\tlogger.DebugContext(ctx, \"Got response element of %v\\n\", v)\n\t\tif v.Name != nil && strings.HasSuffix(*v.Name, \"_raw\") {\n\t\t\tcontinue\n\t\t}\n\t\tif !showHiddenFields && v.Hidden != nil && *v.Hidden {\n\t\t\tcontinue\n\t\t}\n\t\tvMap := make(map[string]any)\n\t\tif v.Name != nil {\n\t\t\tvMap[\"name\"] = *v.Name\n\t\t}\n\t\tif v.Type != nil {\n\t\t\tvMap[\"type\"] = *v.Type\n\t\t}\n\t\tif v.Label != nil {","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/looker/lookercommon/lookercommon.go#L32-L68","documentation":"ExtractLookerFieldProperties fetches the logger from the context via util.LoggerFromContext. If the context carries no logger, it cannot log field extraction progress, so it aborts and returns this error instead of an empty field map.","triggerScenarios":"Calling ExtractLookerFieldProperties with a ctx that never had a logger attached (e.g., a raw context.Background() in tests or a code path bypassing the server's context middleware).","commonSituations":"Unit tests calling the helper directly with a bare context; custom invoke wrappers dropping the logger middleware; background goroutines spawned with a new context.","solutions":["Use the request context propagated by the toolbox server, which embeds the logger.","In tests or standalone code, attach a logger first: ctx := util.ContextWithLogger(ctx, logger).","If spawning goroutines, pass the parent (logger-carrying) context or re-attach the logger."],"exampleFix":"// before\nfields, err := lookercommon.ExtractLookerFieldProperties(context.Background(), resp)\n// after\nlogger := slog.Default()\nctx := util.ContextWithLogger(context.Background(), logger)\nfields, err := lookercommon.ExtractLookerFieldProperties(ctx, resp)\n","handlingStrategy":"validation","validationCode":"// Ensure a logger is present before calling\nif _, err := util.LoggerFromContext(ctx); err != nil {\n    ctx = util.ContextWithLogger(ctx, slog.Default())\n}","typeGuard":null,"tryCatchPattern":"fields, err := lookercommon.ExtractLookerFieldProperties(ctx, resp)\nif err != nil && strings.Contains(err.Error(), \"error getting logger\") {\n    ctx = util.ContextWithLogger(ctx, slog.Default())\n    fields, err = lookercommon.ExtractLookerFieldProperties(ctx, resp)\n}","preventionTips":["Always derive invoke contexts from the server request context.","In tests, use a test helper that attaches a slog logger to every context.","Never spawn goroutines with a brand-new context.Background(); pass the parent ctx."],"tags":["logging","context","looker"],"backgroundTag":"missing-logger-in-context","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}