{"record":{"id":"9daed329846195f9","repo":"lima-vm/lima","slug":"failed-to-unmarshal-q-as-t-w","errorCode":null,"errorMessage":"failed to unmarshal %#q as %T: %w","messagePattern":"failed to unmarshal %#q as %T: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hostagent/events/watcher.go","lineNumber":66,"sourceCode":"\nloop:\n\tfor {\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\tbreak loop\n\t\tcase line := <-haStdoutTail.Lines:\n\t\t\tif line == nil {\n\t\t\t\tbreak loop\n\t\t\t}\n\t\t\tif line.Err != nil {\n\t\t\t\tlogrus.Error(line.Err)\n\t\t\t}\n\t\t\tif line.Text == \"\" {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tvar ev Event\n\t\t\tif err := json.Unmarshal([]byte(line.Text), &ev); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to unmarshal %#q as %T: %w\", line.Text, ev, err)\n\t\t\t}\n\t\t\tlogrus.WithField(\"event\", ev).Debugf(\"received an event\")\n\t\t\tif !begin.IsZero() && ev.Time.Before(begin) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif stop := onEvent(ev); stop {\n\t\t\t\treturn nil\n\t\t\t}\n\t\tcase line := <-haStderrTail.Lines:\n\t\t\tif line == nil {\n\t\t\t\tbreak loop\n\t\t\t}\n\t\t\tif line.Err != nil {\n\t\t\t\tlogrus.Error(line.Err)\n\t\t\t}\n\t\t\tif propagateStderr {\n\t\t\t\tlogrusutil.PropagateJSON(logrus.StandardLogger(), []byte(line.Text), \"[hostagent] \", begin)\n\t\t\t}","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/hostagent/events/watcher.go#L48-L84","documentation":"The hostagent watches the instance's event log/stream and json.Unmarshals each line into an events.Event. When a line is not valid JSON (or not a JSON object matching the Event schema), Watch returns this wrapped error including the raw text and the underlying unmarshal error. It guards against corrupt or truncated event streams.","triggerScenarios":"A line read from the event log file/socket is not valid JSON — e.g. a partially-written/truncated line after a crash, human-edited lima event log, or anything else writing non-JSON text into the same stream.","commonSituations":"VM killed mid-write leaving a half-flushed JSON line; disk full causing truncated writes; an older/newer guestagent writing a different event format; manually inspecting/appending to the lima event log with an editor.","solutions":["Delete the corrupt event log (e.g. ~/.lima/<instance>/ha.log or the event pipe file) and restart the instance so a fresh log is created","Recreate the instance with 'limactl delete <name>' then 'limactl start <name>' if the log keeps regenerating corrupt lines","Check disk space and filesystem health; truncated writes often come from ENOSPC","Inspect the raw line shown in the error to identify what wrote the non-JSON content"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// validate the event log before watching\nlines, _ := os.ReadFile(eventLogPath)\nfor i, l := range bytes.Split(lines, []byte('\\n')) {\n\tif len(l) == 0 { continue }\n\tvar probe map[string]any\n\tif err := json.Unmarshal(l, &probe); err != nil {\n\t\tlog.Printf(\"corrupt event line %d: %v\", i+1, err)\n\t}\n}","typeGuard":"func isValidEventLine(text string) bool {\n\tvar ev events.Event\n\treturn json.Unmarshal([]byte(text), &ev) == nil\n}","tryCatchPattern":"if err := w.Watch(ctx, begin, onEvent); err != nil {\n\tvar unw *json.UnmarshalTypeError\n\tif errors.As(err, &unw) || strings.Contains(err.Error(), \"failed to unmarshal\") {\n\t\t// rotate/truncate corrupt log and retry once\n\t\tos.Remove(eventLogPath)\n\t\treturn w.Watch(ctx, begin, onEvent)\n\t}\n\treturn err\n}","preventionTips":["Never hand-edit or append non-JSON text to Lima's event log files","Ensure adequate disk space so writes are not truncated","Don't mix Lima versions against the same instance directory","Treat event log files as internal state; inspect copies, not originals"],"tags":["json","unmarshal","events","parsing"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}