{"record":{"id":"24743e6e1e2e898b","repo":"gofr-dev/gofr","slug":"surrealdb-w","errorCode":null,"errorMessage":"surrealdb: %w","messagePattern":"surrealdb: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/migration/surreal_db.go","lineNumber":108,"sourceCode":"\tcase uint64:\n\t\tif n > math.MaxInt64 {\n\t\t\treturn 0\n\t\t}\n\n\t\treturn int64(n)\n\tcase float64:\n\t\treturn int64(n)\n\tdefault:\n\t\treturn 0\n\t}\n}\n\nfunc (s surrealMigrator) getLastMigration(c *container.Container) (int64, error) {\n\tvar lastMigration int64\n\n\tresult, err := s.SurrealDB.Query(context.Background(), getLastSurrealDBGoFrMigration, nil)\n\tif err != nil {\n\t\treturn -1, fmt.Errorf(\"surrealdb: %w\", err)\n\t}\n\n\tif len(result) > 0 {\n\t\tif row, ok := result[0].(map[string]any); ok {\n\t\t\tlastMigration = surrealVersionToInt64(row[\"version\"])\n\t\t}\n\t}\n\n\tc.Debugf(\"surrealDB last migration fetched value is: %v\", lastMigration)\n\n\tlm2, err := s.migrator.getLastMigration(c)\n\tif err != nil {\n\t\treturn -1, err\n\t}\n\n\treturn max(lastMigration, lm2), nil\n}\n","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/migration/surreal_db.go#L90-L126","documentation":"This error wraps failures from querying the current migration version in the SurrealDB migrator. getLastMigration runs getLastSurrealDBGoFrMigration via s.SurrealDB.Query; if the query itself errors (connection, auth, query rejection) the error is wrapped with the `surrealdb:` prefix and -1 is returned. It is a migration-state lookup failure, not a data problem.","triggerScenarios":"Calling Migration.Run with a SurrealDB datasource when the SELECT of the gofr_migrations table fails — server unreachable, session expired, table dropped mid-run, invalid query.","commonSituations":"SurrealDB restarted between migration steps; WebSocket connection dropped; wrong namespace/database selected so the table isn't visible; RBAC permissions deny SELECT on the migrations table.","solutions":["Check the inner wrapped error for the SurrealDB cause (auth, permission, connection).","Verify namespace/database selection and that the gofr_migrations table exists.","Reconnect or re-authenticate to SurrealDB, then retry the migration.","Confirm the configured SurrealDB role can SELECT from the migrations table."],"exampleFix":"// before: reading last migration with expired/unstable WS connection\napp.Migrate()\n// after: ensure stable connection and retry on transient failure\nfor i := 0; i < 3; i++ {\n\tif err := pingSurreal(db); err == nil { break }\n\ttime.Sleep(time.Second)\n}\napp.Migrate()","handlingStrategy":"retry","validationCode":"if err := db.Health(ctx); err != nil {\n\treturn fmt.Errorf(\"surrealdb unhealthy before migration: %w\", err)\n}","typeGuard":"if s.SurrealDB == nil {\n\treturn errors.New(\"surrealdb datasource not configured\")\n}","tryCatchPattern":"var last int64\nvar err error\nfor i := 0; i < 3; i++ {\n\tlast, err = migrator.getLastMigration(c)\n\tif err == nil { break }\n\ttime.Sleep(500 * time.Millisecond) // transient WS drops\n}\nif err != nil { return fmt.Errorf(\"last migration lookup failed: %w\", err) }","preventionTips":["Retry transient SurrealDB errors — WebSocket connections can drop.","Verify ns/db selection matches where migrations were previously applied.","Confirm RBAC/permissions allow SELECT on gofr_migrations.","Monitor SurrealDB liveness during long migration runs."],"tags":["surrealdb","migration","database","gofr"],"backgroundTag":"sql-query-failed","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}