Skip to content

Commit

Permalink
fix(cfg): Better error messages when validating config
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop committed Aug 13, 2019
1 parent 46c0481 commit 6ee7355
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (cfg Config) Validate() error {
}
}`)
if err := validate(schema, &cfg); err != nil {
return err
return fmt.Errorf("config validation error: %s", err)
}

validators := []validator{
Expand Down
2 changes: 1 addition & 1 deletion config/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type P2P struct {
// ProfileReplication determines what to do when this peer sees messages
// broadcast by it's own profile (from another peer instance). setting
// ProfileReplication == "full" will cause this peer to automatically pin
// any data that is verifyably posted by the same peer
// any data that is verifiably posted by the same peer
ProfileReplication string `json:"profilereplication"`

// list of addresses to bootsrap qri peers on
Expand Down
13 changes: 8 additions & 5 deletions lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ func OptConfig(cfg *config.Config) Option {
func OptSetIPFSPath(path string) Option {
return func(o *InstanceOptions) error {
if o.Cfg == nil {
return fmt.Errorf("no config file to set IPFS path on")
return fmt.Errorf("config is nil, can't set IPFS path")
}
if o.Cfg.Store == nil {
return fmt.Errorf("config.Store is nil, can't check type")
}
if o.Cfg.Store.Type == "ipfs" && o.Cfg.Store.Path == "" {
if path == "" {
Expand Down Expand Up @@ -228,7 +231,7 @@ func NewInstance(ctx context.Context, repoPath string, opts ...Option) (qri *Ins
}

if inst.cron, err = newCron(cfg, inst.repoPath); err != nil {
return
return nil, fmt.Errorf("newCron: %s", err)
}

// check if we're operating over RPC
Expand All @@ -244,15 +247,15 @@ func NewInstance(ctx context.Context, repoPath string, opts ...Option) (qri *Ins
}

if inst.store, err = newStore(ctx, cfg); err != nil {
return
return nil, fmt.Errorf("newStore: %s", err)
}
if inst.qfs, err = newFilesystem(cfg, inst.store); err != nil {
return
return nil, fmt.Errorf("newFilesystem: %s", err)
}
inst.registry = newRegClient(cfg)

if inst.repo, err = newRepo(inst.repoPath, cfg, inst.store, inst.registry); err != nil {
return
return nil, fmt.Errorf("newRepo: %s", err)
}
if qfssetter, ok := inst.repo.(repo.QFSSetter); ok {
qfssetter.SetFilesystem(inst.qfs)
Expand Down
4 changes: 2 additions & 2 deletions repo/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ func NewProfile(p *config.ProfilePod) (pro *Profile, err error) {
func (p *Profile) Decode(sp *config.ProfilePod) error {
id, err := IDB58Decode(sp.ID)
if err != nil {
return err
return fmt.Errorf("parsing profile.ID \"%s\": %s", sp.ID, err)
}

t, err := ParseType(sp.Type)
if err != nil {
return err
return fmt.Errorf("parsing profileType \"%s\": %s", sp.Type, err)
}

pids := make([]peer.ID, len(sp.PeerIDs))
Expand Down

0 comments on commit 6ee7355

Please sign in to comment.