Skip to content

Commit

Permalink
Make err for already published document
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Mar 17, 2024
1 parent 90773c2 commit a93a310
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion did/doc/publication.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package doc

import (
"context"
"errors"
"fmt"
"sync"

Expand All @@ -14,6 +15,8 @@ import (
log "github.com/sirupsen/logrus"
)

var ErrAlreadyPublished = errors.New("Document is already published")

type PublishOptions struct {
Ctx context.Context
Pin bool
Expand All @@ -36,6 +39,7 @@ func DefaultPublishOptions() *PublishOptions {
// It's about publishing the document to IPNS and possibly pinning it.
func (d *Document) Publish(o ...*PublishOptions) (ipns.Name, error) {

alreadyPublishedString := "'to' cid was already recursively pinned"
opts := DefaultPublishOptions()

// Iterate through all options provided
Expand Down Expand Up @@ -84,7 +88,9 @@ func (d *Document) Publish(o ...*PublishOptions) (ipns.Name, error) {
if err == nil && c != e && opts.Pin && opts.Force {
err := a.Pin().Update(opts.Ctx, path.FromCid(e), p)
if err != nil {
// Not sure if this is "fatal" or not. We should probably return the error and let the caller decide.
if err.Error() == alreadyPublishedString {
return ipns.Name{}, fmt.Errorf("DocPublish: %w", ErrAlreadyPublished)
}
return ipns.Name{}, fmt.Errorf("DocPublish: %w", err)
}
} else {
Expand All @@ -94,6 +100,7 @@ func (d *Document) Publish(o ...*PublishOptions) (ipns.Name, error) {
log.Debugf("DocPublish: Announcing publication of document %s to IPNS. Please wait ...", c.String())
n, err := a.Name().Publish(opts.Ctx, p, caopts.Name.Key(ik.Fragment))
if err != nil {

return ipns.Name{}, fmt.Errorf("DocPublish: %w", err)
}
log.Debugf("DocPublish: Successfully announced publication of document %s to %s", c.String(), n.AsPath().String())
Expand Down
2 changes: 1 addition & 1 deletion msg/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Message struct {
To string `cbor:"to"`
// MIME type of the message body
ContentType string `cbor:"contentType"`
// Hexadecimal string representation of the SHA-256 hash of the message body
// Byte slice of the content
Content []byte `cbor:"content"`
// Signature of the message headers. NB! This includes the ContentHash field,
// which can be used to verify the integrity of the message body.
Expand Down

0 comments on commit a93a310

Please sign in to comment.