{"record":{"id":"d3934372c971ede2","repo":"LykosAI/StabilityMatrix","slug":"fields-line-not-found","errorCode":null,"errorMessage":"Fields line not found","messagePattern":"Fields line not found","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Models/GenerationParameters.cs","lineNumber":69,"sourceCode":"        {\n            generationParameters = Parse(text);\n        }\n        catch (Exception)\n        {\n            generationParameters = null;\n            return false;\n        }\n\n        return true;\n    }\n\n    public static GenerationParameters Parse(string text)\n    {\n        var lines = text.Split('\\n');\n\n        if (lines.LastOrDefault() is not { } lastLine)\n        {\n            throw new ValidationException(\"Fields line not found\");\n        }\n\n        if (lastLine.StartsWith(\"Steps:\") != true)\n        {\n            lines = text.Split(\"\\r\\n\");\n            lastLine = lines.LastOrDefault() ?? string.Empty;\n\n            if (lastLine.StartsWith(\"Steps:\") != true)\n            {\n                throw new ValidationException(\"Unable to locate starting marker of last line\");\n            }\n        }\n\n        // Join lines before last line, split at 'Negative prompt: '\n        var joinedLines = string.Join(\"\\n\", lines[..^1]).Trim();\n\n        // Apparently there is no space after the colon if value is empty, so check and add space here\n        if (joinedLines.EndsWith(\"Negative prompt:\"))","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Models/GenerationParameters.cs#L51-L87","documentation":"GenerationParameters.Parse parses plaintext generation-parameter blocks (e.g. from PNG metadata). It splits the text into lines and expects the last line to be the 'Fields:'-style parameter line starting with 'Steps:'; when the text has no usable last line it throws ValidationException('Fields line not found'). This guards against empty or unparseable prompt payloads.","triggerScenarios":"Calling GenerationParameters.Parse (or TryParse) with an empty string, a prompt without a trailing parameter line, or metadata text where parameters were stripped; also when only '\\r\\n' line endings exist and the last-line check on the first split fails before the CRLF retry.","commonSituations":"Importing images generated by other tools that omit the A1111-style footer; user-edited prompt text with the parameters line deleted; exotic line endings defeating the split.","solutions":["Verify the text contains a trailing line starting with 'Steps:' before parsing","Use TryParse instead of Parse so parse failures return false instead of throwing","Normalize line endings (replace '\\r\\n' with '\\n') before parsing","Extract parameters only from images known to carry A1111-style metadata"],"exampleFix":"// before\nvar parameters = GenerationParameters.Parse(metadataText);\n// after\nif (!GenerationParameters.TryParse(metadataText, out var parameters))\n{\n    Logger.Debug(\"No generation parameters in metadata\");\n    return GenerationParameters.Default;\n}","handlingStrategy":"type-guard","validationCode":"static bool LooksLikeGenerationParameters(string text) =>\n    !string.IsNullOrWhiteSpace(text) &&\n    text.Split(new[]{'\\n','\\r'}).LastOrDefault(l => !string.IsNullOrWhiteSpace(l))?.StartsWith(\"Steps:\") == true;","typeGuard":"bool TryGetParameters(string? text, out GenerationParameters parameters) =>\n    GenerationParameters.TryParse(text, out parameters) ;","tryCatchPattern":"try { parameters = GenerationParameters.Parse(text); }\ncatch (ValidationException) { parameters = null; /* no parameter footer in metadata */ }","preventionTips":["Prefer TryParse over Parse for untrusted metadata","Normalize CRLF line endings before parsing","Only parse metadata known to contain A1111-style footers","Return defaults instead of throwing when parameters are absent"],"tags":["csharp","parsing","metadata","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}