{"record":{"id":"e00e34b546cf750b","repo":"apache/beam","slug":"err-end-estimator","errorCode":null,"errorMessage":"err","messagePattern":"err","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/natsio/end_estimator.go","lineNumber":44,"sourceCode":"type endEstimator struct {\n\tjs      jetstream.JetStream\n\tstream  string\n\tsubject string\n}\n\nfunc newEndEstimator(js jetstream.JetStream, stream string, subject string) *endEstimator {\n\treturn &endEstimator{\n\t\tjs:      js,\n\t\tstream:  stream,\n\t\tsubject: subject,\n\t}\n}\n\nfunc (e *endEstimator) Estimate() int64 {\n\tctx := context.Background()\n\tend, err := e.getEndSeqNo(ctx)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn end\n}\n\nfunc (e *endEstimator) getEndSeqNo(ctx context.Context) (int64, error) {\n\tstr, err := e.js.Stream(ctx, e.stream)\n\tif err != nil {\n\t\treturn -1, fmt.Errorf(\"error getting stream: %v\", err)\n\t}\n\n\tmsg, err := str.GetLastMsgForSubject(ctx, e.subject)\n\tif err != nil {\n\t\tif isMessageNotFound(err) {\n\t\t\treturn 1, nil\n\t\t}\n\n\t\treturn -1, fmt.Errorf(\"error getting last message: %v\", err)\n\t}","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/natsio/end_estimator.go#L26-L62","documentation":"natsio's endEstimator.Estimate panics when getEndSeqNo fails to fetch the stream's latest sequence number from JetStream. The estimate is used internally for sizing a read range, and there is no error channel in the estimator interface, so failure escalates to a panic. This indicates a JetStream API/connectivity problem, not a data issue.","triggerScenarios":"Calling Estimate (during pipeline setup/estimation) when the NATS server is unreachable, the stream name does not exist (js.Stream returns ErrStreamNotFound), credentials are rejected, or the JetStream request times out.","commonSituations":"Typo in stream name; NATS server without JetStream enabled; network/auth problems between the worker and NATS; stream deleted after connection was established.","solutions":["Verify the stream name passed to natsio matches an existing JetStream stream (nats stream info <name>)","Confirm JetStream is enabled on the server and reachable with the given credentials","Check that the NATS connection context/auth config is valid from the execution environment","Wrap the estimator call with recover() or pre-check the stream existence with js.StreamInfo yourself"],"exampleFix":"// before\nend := estimator.Estimate() // panics if stream missing\n// after\nif _, err := js.StreamInfo(ctx, streamName); err != nil {\n    log.Fatalf(\"stream %q not available: %v\", streamName, err)\n}\nend := estimator.Estimate()","handlingStrategy":"try-catch","validationCode":"if _, err := js.StreamInfo(ctx, streamName); err != nil {\n    return fmt.Errorf(\"stream %q unavailable: %w\", streamName, err)\n}","typeGuard":null,"tryCatchPattern":"defer func() { if r := recover(); r != nil { log.Fatalf(\"natsio estimate: %v\", r) } }()","preventionTips":["Verify stream names exist before launching the pipeline","Enable and verify JetStream on the NATS servers","Add retry/timeout tuning for JetStream requests in flaky networks"],"tags":["go","nats","jetstream","panic","network"],"backgroundTag":"resource-not-found","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}