{"record":{"id":"ae7829f5b1108a1d","repo":"wtfutil/wtf","slug":"failed-to-read-query-file-s-w","errorCode":null,"errorMessage":"failed to read query file %s: %w","messagePattern":"failed to read query file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/azurelogs/session.go","lineNumber":29,"sourceCode":"const (\n\tenvAzureClientID     = \"AZURE_CLIENT_ID\"\n\tenvAzureClientSecret = \"AZURE_CLIENT_SECRET\"\n\tenvAzureTenantID     = \"AZURE_TENANT_ID\"\n)\n\n// Init initializes a new Azure session with the specified query file\nfunc Init(queryPath *string) (*Session, error) {\n\tsess := &Session{}\n\tsess.Azure = &AZSession{}\n\n\t// Initialize Azure authentication using modern non-deprecated libraries\n\tif err := InitializeAzureAuthentication(sess); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to initialize Azure authentication: %w\", err)\n\t}\n\n\terr := readQueryFile(sess, *queryPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read query file %s: %w\", *queryPath, err)\n\t}\n\n\treturn sess, nil\n}\n\n// Session holds the configuration and state for an Azure Log Analytics session\ntype Session struct {\n\tApp struct {\n\t\tSemVer string\n\t}\n\n\tAzure       *AZSession\n\tQueriesPath string\n\tQueryFile   QueryFile\n}\n\n// AZClientSecretCredential holds Azure service principal credentials\ntype AZClientSecretCredential struct {","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/modules/azurelogs/session.go#L11-L47","documentation":"Init in modules/azurelogs/session.go:29 wraps any error from readQueryFile with this message, embedding the query file path. readQueryFile in turn can fail on file reads or YAML parsing (see error 40), so this is the outermost wrapper for all query-config loading problems. Authentication (line 24) has already succeeded when this fires.","triggerScenarios":"Calling Init(queryPath) where the query file does not exist, is unreadable (permissions), is a directory, or contains invalid YAML — any non-nil error returned by readQueryFile.","commonSituations":"Typo'd or relative path resolved from the wrong working directory, file not mounted into a container, permissions changed by deployment, or malformed YAML as in error 40.","solutions":["Verify the path passed to Init exists: `ls -la <path>` (use an absolute path or correct the working directory)","Check file read permissions for the user running the process","If the wrapped error mentions YAML parsing, fix the YAML syntax in the file (see error 40)","In containers, confirm the query file is copied/mounted into the image at the expected path"],"exampleFix":"// before\nsess, err := azurelogs.Init(ptr.To(\"queries.yml\"))  // wrong CWD, file not found\n// after\nsess, err := azurelogs.Init(ptr.To(\"/etc/azurelogs/queries.yml\"))  // absolute path","handlingStrategy":"validation","validationCode":"func validateQueryPath(p string) error {\n    info, err := os.Stat(p)\n    if err != nil {\n        return fmt.Errorf(\"query file not accessible at %s: %w\", p, err)\n    }\n    if info.IsDir() {\n        return fmt.Errorf(\"%s is a directory, expected a YAML file\", p)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := validateQueryPath(queryPath); err == nil {\n    sess, err = azurelogs.Init(&queryPath)\n}\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to read query file\") {\n        return fmt.Errorf(\"check path/permissions/YAML for %s: %w\", queryPath, err)\n    }\n    return err\n}","preventionTips":["Pass absolute paths to Init to avoid CWD surprises","os.Stat the path before calling Init and surface a clear error","In containers, verify the query file is COPY'd/mounted and readable by the runtime user","Validate and lint query files as a CI step before deployment"],"tags":["azure","config","file-io","session-init"],"backgroundTag":"config-file-not-found","analyzedSha":"bb838c1ccb0f0f3223690df44afdec663d622881","analyzedAt":"2026-09-03T17:02:45.030Z","contentChangedAt":"2026-09-03T17:02:45.030Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}