{"record":{"id":"92b65b2eefdc5ea4","repo":"henrygd/beszel","slug":"unexpected-dest-type-for-getsmartdata-t","errorCode":null,"errorMessage":"unexpected dest type for GetSmartData: %T","messagePattern":"unexpected dest type for GetSmartData: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hub/transport/transport.go","lineNumber":106,"sourceCode":"\t\t*d = *resp.String\n\t\treturn nil\n\tcase common.GetSmartData:\n\t\tswitch d := dest.(type) {\n\t\tcase *map[string]smart.SmartData:\n\t\t\tif resp.SmartData == nil {\n\t\t\t\treturn errors.New(\"no SMART data in response\")\n\t\t\t}\n\t\t\t*d = resp.SmartData\n\t\t\treturn nil\n\t\tcase *smart.SmartDataResponse:\n\t\t\tif resp.SmartData == nil {\n\t\t\t\treturn errors.New(\"no SMART data in response\")\n\t\t\t}\n\t\t\td.Data = resp.SmartData\n\t\t\td.Complete = resp.SmartComplete\n\t\t\treturn nil\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"unexpected dest type for GetSmartData: %T\", dest)\n\t\t}\n\tcase common.GetSystemdInfo:\n\t\td, ok := dest.(*systemd.ServiceDetails)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"unexpected dest type for GetSystemdInfo: %T\", dest)\n\t\t}\n\t\tif resp.ServiceInfo == nil {\n\t\t\treturn errors.New(\"no systemd info in response\")\n\t\t}\n\t\t*d = resp.ServiceInfo\n\t\treturn nil\n\t}\n\treturn fmt.Errorf(\"unsupported action: %d\", action)\n}\n","sourceCodeStart":88,"sourceCodeEnd":121,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/internal/hub/transport/transport.go#L88-L121","documentation":"unmarshalLegacyResponse handles legacy (0.18.0) agent responses with typed fields. For GetSmartData it accepts only *map[string]smart.SmartData or *smart.SmartDataResponse as the destination. This error means the caller passed some other pointer type, so the legacy response cannot be copied into it.","triggerScenarios":"Calling Transport.Request (or UnmarshalResponse) with action common.GetSmartData while dest is a pointer to a type other than map[string]smart.SmartData or smart.SmartDataResponse, AND the agent response has an empty Data field (pre-0.19 agent), forcing the legacy path.","commonSituations":"Mixing hub/agent versions where legacy responses are still in play; refactoring code to use a custom SMART result struct; passing *smart.SmartData instead of *map[string]smart.SmartData.","solutions":["Change the dest argument to *map[string]smart.SmartData or *smart.SmartDataResponse for GetSmartData requests","Upgrade the agent to 0.19+ so responses use the generic CBOR Data field, which unmarshals into any dest type","Check the caller of UnmarshalResponse to ensure the dest type matches the action constant"],"exampleFix":"// before\nvar data smart.SmartData\nerr := t.Request(ctx, common.GetSmartData, nil, &data)\n// after\nvar data map[string]smart.SmartData\nerr := t.Request(ctx, common.GetSmartData, nil, &data)","handlingStrategy":"type-guard","validationCode":"if _, ok := dest.(*map[string]smart.SmartData); !ok {\n    if _, ok2 := dest.(*smart.SmartDataResponse); !ok2 {\n        return fmt.Errorf(\"GetSmartData dest must be *map[string]smart.SmartData or *smart.SmartDataResponse, got %T\", dest)\n    }\n}","typeGuard":"func isSmartDataDest(dest any) bool {\n    switch dest.(type) {\n    case *map[string]smart.SmartData, *smart.SmartDataResponse:\n        return true\n    }\n    return false\n}","tryCatchPattern":"if err := t.Request(ctx, common.GetSmartData, nil, dest); err != nil {\n    var terr *transportError\n    if strings.Contains(err.Error(), \"unexpected dest type\") { /* fix dest type */ }\n    return err\n}","preventionTips":["Always pass *map[string]smart.SmartData or *smart.SmartDataResponse for GetSmartData","Keep hub and agent versions in sync (0.19+ uses the generic CBOR path)","Add a unit test asserting dest types accepted per action"],"tags":["type-mismatch","legacy-response","smart-data"],"backgroundTag":"unexpected-destination-type","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}