{"record":{"id":"a5d851412bfe8c58","repo":"builtbybel/FlyOOBE","slug":"null","errorCode":null,"errorMessage":"null","messagePattern":"null","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Flyby11-deprecated/Flyby11/Logger.cs","lineNumber":14,"sourceCode":"﻿using System;\nusing System.Drawing;\nusing System.Linq;\nusing System.Windows.Forms;\n\nnamespace Flyby11\n{\n    public class Logger\n    {\n        private MainForm mainForm;\n\n        public Logger(MainForm mainForm)\n        {\n            this.mainForm = mainForm ?? throw new ArgumentNullException(nameof(mainForm));\n        }\n\n        // Log method for a single string\n        public void Log(string message, Color color, float fontSize = 10.5f)\n        {\n            if (mainForm.InvokeRequired)\n            {\n                mainForm.Invoke(new Action(() => Log(message, color, fontSize)));\n                return;\n            }\n\n\n            AppendMessageToConversation(message, color, fontSize);             // Append message to conversation\n        }\n\n        private void AppendMessageToConversation(string message, Color color, float fontSize)\n        {\n            Label statusLabel = mainForm.Controls.Find(\"statusLabel\", true).FirstOrDefault() as Label;","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/builtbybel/FlyOOBE/blob/ed093a784df51b19e989395f2ed6443ca1f335dd/Flyby11-deprecated/Flyby11/Logger.cs#L1-L32","documentation":"The Logger constructor validates that a MainForm instance is provided, since every log entry must be rendered onto that form's UI (it calls mainForm.InvokeRequired/Invoke). If null is passed, it throws ArgumentNullException immediately rather than failing later on the first log call.","triggerScenarios":"Calling `new Logger(null)` — e.g. before the MainForm instance is constructed, passing an uninitialized form field, or constructing a Logger in a static context where the form reference is not yet assigned.","commonSituations":"Refactoring the app startup so the Logger is created before InitializeComponent of the main form; passing a different Form type that is null; unit-testing Logger without a form instance; dependency-injection container not registered for MainForm.","solutions":["Pass a valid, already-constructed MainForm instance to the Logger constructor","Ensure MainForm is created before Logger (reorder startup code)","If the form may not exist yet, defer Logger creation until after form construction, or make mainForm nullable and buffer logs","In tests, pass a stub MainForm or refactor Logger to accept an abstraction (e.g. Action<string> sink)"],"exampleFix":"// before\nvar logger = new Logger(null);\n// after\nMainForm mainForm = new MainForm();\nvar logger = new Logger(mainForm);","handlingStrategy":"validation","validationCode":"if (mainForm == null)\n    throw new InvalidOperationException(\"MainForm must be constructed before creating a Logger\");\nvar logger = new Logger(mainForm);","typeGuard":"bool IsValidLoggerTarget(MainForm form) => form != null && !form.IsDisposed;","tryCatchPattern":"try\n{\n    var logger = new Logger(mainForm);\n}\ncatch (ArgumentNullException ex)\n{\n    // ex.ParamName == \"mainForm\"\n    LogFallback(\"Logger init failed: main form reference was null\");\n}","preventionTips":["Construct MainForm before any component that depends on it","Check form references for null/IsDisposed before wiring loggers","Prefer constructor injection with a DI container so null dependencies fail at composition time","Unit-test Logger construction with a stub form"],"tags":["csharp","winforms","argumentnull","logging"],"backgroundTag":"null-argument","analyzedSha":"ed093a784df51b19e989395f2ed6443ca1f335dd","analyzedAt":"2026-09-14T12:05:30.440Z","contentChangedAt":"2026-09-14T12:05:30.440Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}