Skip to content

Commit f4fb071

Browse files
stapelbergcopybara-github
authored andcommitted
print frequent mistakes when rewrite fails, improve error output
fixes #10 PiperOrigin-RevId: 716183954 Change-Id: Id92cf0508575eda89b761d77e62e22d308de92bb
1 parent 6c944b1 commit f4fb071

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

internal/o2o/rewrite/rewrite.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func (cmd *Cmd) RewriteTargets(ctx context.Context, targets []string) error {
348348
}
349349

350350
if err := rewrite(ctx, cfg); err != nil {
351-
log.ExitContext(ctx, err)
351+
return err
352352
}
353353

354354
return nil
@@ -534,13 +534,33 @@ func rewrite(ctx context.Context, cfg *config) (err error) {
534534
fmt.Fprintf(os.Stderr, "Can't fix builds: %v\n", err)
535535
}
536536
}
537+
fmt.Println()
537538
if fail > 0 {
538-
return fmt.Errorf("%d packages could not be rewritten", fail)
539+
return fmt.Errorf(rewriteFailedFmt, fail)
539540
}
540541

541542
return nil
542543
}
543544

545+
const rewriteFailedFmt = `%d packages could not be rewritten
546+
547+
Frequent mistakes include:
548+
549+
- Enabling the Opaque API before rewriting your code.
550+
Instead, set your .proto files to the Hybrid API
551+
before running open2opaque rewrite. For details, see
552+
https://protobuf.dev/reference/go/opaque-migration/
553+
554+
- Your code must build for the open2opaque tool to work.
555+
Check that a build shows no errors: go build ./...
556+
557+
- Incorrectly migrating .proto files to edition 2023.
558+
It is not sufficient to only replace the syntax line.
559+
To preserve your current behavior (proto2 or proto3)
560+
when migrating to edition 2023, follow this document:
561+
https://protobuf.dev/editions/features/#preserving
562+
`
563+
544564
func runGoimports(dir string, files []string) error {
545565
fmt.Printf("\tRunning goimports on %d files\n", len(files))
546566
// Limit concurrent processes.

0 commit comments

Comments
 (0)