{"record":{"id":"b6ae1e37e7e2b841","repo":"projectdiscovery/katana","slug":"unknown-tag-q","errorCode":null,"errorMessage":"unknown tag %q","messagePattern":"unknown tag %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/output/format_template.go","lineNumber":28,"sourceCode":")\n\nfunc (w *StandardWriter) formatTemplate(output *Result) ([]byte, error) {\n\tvar fieldOutputs []fieldOutput\n\tfieldNames := strings.Join(FieldNames, \",\")\n\tfieldOutputs = formatField(output, fieldNames)\n\tfieldOutputs = append(fieldOutputs, getValueForCustomField(output)...)\n\n\tfieldsMap := make(map[string]string)\n\tfor _, fo := range fieldOutputs {\n\t\tfieldsMap[fo.field] = fo.value\n\t}\n\n\terrUnknownTag := errors.New(\"unknown tag\")\n\n\ttagFn := fasttemplate.TagFunc(func(w io.Writer, tag string) (int, error) {\n\t\tvalue, ok := fieldsMap[tag]\n\t\tif !ok {\n\t\t\treturn 0, fmt.Errorf(\"%w %q\", errUnknownTag, tag)\n\t\t}\n\t\treturn w.Write([]byte(value))\n\t})\n\n\tout, err := w.outputTemplate.ExecuteFuncStringWithErr(tagFn)\n\tif err != nil {\n\t\tif errors.Is(err, errUnknownTag) {\n\t\t\t// If there is an unknown tag, we just ignore it.\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn nil, err\n\t}\n\n\treturn []byte(out), nil\n}\n","sourceCodeStart":10,"sourceCodeEnd":44,"githubUrl":"https://github.com/projectdiscovery/katana/blob/e3e742739c3746f085943ce918fb4e2b8daf6fe6/pkg/output/format_template.go#L10-L44","documentation":"formatTemplate wraps a sentinel errUnknownTag with the offending tag name when a fasttemplate placeholder in the output template does not exist among the result's fields ({{...}} tags not found in fieldsMap). Notably, the writer intentionally swallows this case and returns (nil, nil), ignoring unknown tags and skipping that output line.","triggerScenarios":"Using -f/-output-template (or custom template options) with a tag like {{nonexistent-field}} that is not in FieldNames nor a custom field (format_template.go:28).","commonSituations":"Typo in template field names ({{rul}} instead of {{url}}); using custom-field placeholders that were never defined; copying templates across katana versions where field names changed.","solutions":["Fix the template to use only supported fields (see output.FieldNames) or define the custom field","If custom code calls formatTemplate directly, match errors.Is(err, errUnknownTag) and ignore as the library does","Test the template on a single result to catch typos early"],"exampleFix":"// before\ntemplate: \"[{{url}}] {{statuz}}\" // typo\n// after\ntemplate: \"[{{url}}] {{status}}\"","handlingStrategy":"validation","validationCode":"func validateTemplate(tmpl string) error {\n    for _, tag := range extractTags(tmpl) {\n        if !slices.Contains(output.FieldNames, tag) && !isCustomField(tag) {\n            return fmt.Errorf(\"unknown template tag: %s\", tag)\n        }\n    }\n    return nil\n}","typeGuard":"func isUnknownTag(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"unknown tag\")\n}","tryCatchPattern":"out, err := w.formatTemplate(result)\nif err != nil && errors.Is(err, errUnknownTag) {\n    return nil, nil // ignore unknown tags, as the library does\n}","preventionTips":["Use only documented field names in -f/-output-template","Verify custom fields are defined before referencing them","Lint templates against output.FieldNames before running large crawls"],"tags":["output","template","fasttemplate"],"backgroundTag":"unknown-template-tag","analyzedSha":"e3e742739c3746f085943ce918fb4e2b8daf6fe6","analyzedAt":"2026-09-03T14:55:13.248Z","contentChangedAt":"2026-09-03T14:55:13.248Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}