Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions cli/command/publish/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ type tarballSizeCounter struct {
total int64
}

type idempotencyRespError struct {
message string
}

func (e *idempotencyRespError) Error() string {
return e.message
}

func (c *tarballSizeCounter) Write(p []byte) (n int, err error) {
c.total += int64(len(p))
return len(p), nil
Expand Down Expand Up @@ -219,13 +227,17 @@ func runPublish(wpmCli command.Cli, opts publishOptions) error {
if err != nil {
return err
}
if resp.Id == "" {
if resp.Message != nil {
return &idempotencyRespError{message: *resp.Message}
}

if resp.Id == nil {
Comment thread
thelovekesh marked this conversation as resolved.
return errors.New("failed to get request id from upload response")
}
reqId = resp.Id
reqId = *resp.Id

if resp.Url != "" {
req, err := http.NewRequestWithContext(context.Background(), http.MethodPut, resp.Url, tempTarball)
if resp.Url != nil {
req, err := http.NewRequestWithContext(context.Background(), http.MethodPut, *resp.Url, tempTarball)
if err != nil {
return err
}
Expand Down Expand Up @@ -254,7 +266,12 @@ func runPublish(wpmCli command.Cli, opts publishOptions) error {
wpmCli.Err(),
)
if err != nil {
return errors.Wrap(err, "failed to upload tarball to registry")
if _, ok := err.(*idempotencyRespError); ok {
fmt.Fprintf(wpmCli.Err(), "🚀 %s 🚀\n", aec.GreenF.Apply(err.Error()))
return nil
}

return err
Comment thread
thelovekesh marked this conversation as resolved.
}

readmeText, err := readme(cwd)
Expand Down
7 changes: 5 additions & 2 deletions cli/registry/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ type UploadTarballOptions struct {

// UploadTarballResponse defines the response structure for uploading a package.
type UploadTarballResponse struct {
Id string `json:"id"`
Url string `json:"url"`
Id *string `json:"id"`
Url *string `json:"url"`

// In case of idempotent requests, the message field may contain information.
Message *string `json:"message,omitempty"`
}

func (c *client) GetUploadTarballUrl(ctx context.Context, opts UploadTarballOptions) (UploadTarballResponse, error) {
Expand Down
Loading