Skip to content

Better error reporting for non-building code (e.g. moved to Opaque directly instead of Hybrid) #10

@johanbrandhorst

Description

@johanbrandhorst

Hi, I was trying out the tool today and ran into what I think is a failure (or I could be using it wrong). Given code that looks like this (in /services/athlete/activity.go):

package athlete

import (
	"context"
	"fmt"

	"connectrpc.com/connect"
	athletesv1 "github.com/catzkorn/trail-tools/gen/athletes/v1"
	"github.com/catzkorn/trail-tools/oidc"
	"github.com/catzkorn/trail-tools/store"
	"google.golang.org/protobuf/types/known/timestamppb"
)

func (s *Service) CreateActivity(ctx context.Context, req *connect.Request[athletesv1.CreateActivityRequest]) (*connect.Response[athletesv1.CreateActivityResponse], error) {
	_, ok := oidc.GetUserInfo(ctx)
	if !ok {
		return nil, connect.NewError(connect.CodeUnauthenticated, fmt.Errorf("unauthenticated"))
	}
	athleteID, err := store.StringToUUID(req.Msg.AthleteId)
	if err != nil {
		return nil, connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("invalid athlete ID: %w", err))
	}
	activity, err := s.athletes.AddActivity(ctx, req.Msg.Name, athleteID)
	if err != nil {
		return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("failed to add activity: %w", err))
	}
	return connect.NewResponse(&athletesv1.CreateActivityResponse{
		Activity: &athletesv1.Activity{
			Id:         store.UUIDToString(activity.ID),
			AthleteId:  store.UUIDToString(activity.AthleteID),
			Name:       req.Msg.Name,
			CreateTime: timestamppb.New(activity.CreateTime.Time),
		},
	}), nil
}

And the command

$ go run google.golang.org/open2opaque@latest rewrite ./services/athlete

I saw this error:

rewriting 1 packages:
  github.com/catzkorn/trail-tools/services/athlete
Starting the Blaze loader
Loading packages (in batches of up to 20)...
PROCESSED 1 packages (total patterns: 1)
        Last package:         github.com/catzkorn/trail-tools/services/athlete
        Total time:           161.676935ms
        Package profile:      TOTAL: 1.47597ms | start 292ns main/scheduled 1.46972ms main/fixed 5.666µs main/gotresp 292ns done
        Failures:             1 (100.00%)
        Average time:         161.676935ms
        Estimated until done: 0s
        Estimated done at:    2025-01-01 17:50:31.795823537 -0800 PST m=+0.239883240
        Error:                panic: can't process package: don't know type for expression *dst.Ident      0  *dst.Ident {
     1  .  Name: "AthleteId"
     2  .  Path: ""
     3  .  Decs: dst.IdentDecorations {
     4  .  .  NodeDecs: dst.NodeDecs {
     5  .  .  .  Before: None
     6  .  .  .  After: None
     7  .  .  }
     8  .  }
     9  }



Processed 1 packages:
        successfully analyzed: 0
        failed to load/rewrite: 1
        .go files rewritten: 0
F0101 17:50:31.795940  832174 rewrite.go:347] rewrite() failed: 1 packages could not be rewritten
exit status 1

This was my first attempt at using the tool, so I could be holding it wrong.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions