Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: logdog/common/types/streamaddr.go

Issue 2963503003: [errors] Greatly simplify common/errors package. (Closed)
Patch Set: fix nits Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « logdog/common/storage/entry.go ('k') | logdog/server/archivist/archivist.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package types 5 package types
6 6
7 import ( 7 import (
8 "flag" 8 "flag"
9 "net/url" 9 "net/url"
10 "strings" 10 "strings"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 // ParseURL parses a LogDog URL into a Stream. If the URL is malformed, or 73 // ParseURL parses a LogDog URL into a Stream. If the URL is malformed, or
74 // if the host, project, or path is invalid, an error will be returned. 74 // if the host, project, or path is invalid, an error will be returned.
75 // 75 //
76 // A LogDog URL has the form: 76 // A LogDog URL has the form:
77 // logdog://<host>/<project>/<prefix>/+/<name> 77 // logdog://<host>/<project>/<prefix>/+/<name>
78 func ParseURL(v string) (*StreamAddr, error) { 78 func ParseURL(v string) (*StreamAddr, error) {
79 u, err := url.Parse(v) 79 u, err := url.Parse(v)
80 if err != nil { 80 if err != nil {
81 » » return nil, errors.Annotate(err).Reason("failed to parse URL").E rr() 81 » » return nil, errors.Annotate(err, "failed to parse URL").Err()
82 } 82 }
83 83
84 // Validate Scheme. 84 // Validate Scheme.
85 if u.Scheme != logDogURLScheme { 85 if u.Scheme != logDogURLScheme {
86 » » return nil, errors.Reason("URL scheme %(scheme)q is not "+logDog URLScheme). 86 » » return nil, errors.Reason("URL scheme %q is not %s", u.Scheme, l ogDogURLScheme).Err()
87 » » » D("scheme", u.Scheme).
88 » » » Err()
89 } 87 }
90 addr := StreamAddr{ 88 addr := StreamAddr{
91 Host: u.Host, 89 Host: u.Host,
92 } 90 }
93 91
94 parts := strings.SplitN(u.Path, "/", 3) 92 parts := strings.SplitN(u.Path, "/", 3)
95 if len(parts) != 3 || len(parts[0]) != 0 { 93 if len(parts) != 3 || len(parts[0]) != 0 {
96 » » return nil, errors.Reason("URL path does not include both projec t and path components: %(path)s"). 94 » » return nil, errors.Reason("URL path does not include both projec t and path components: %s", u.Path).Err()
97 » » » D("path", u.Path).
98 » » » Err()
99 } 95 }
100 96
101 addr.Project, addr.Path = cfgtypes.ProjectName(parts[1]), StreamPath(par ts[2]) 97 addr.Project, addr.Path = cfgtypes.ProjectName(parts[1]), StreamPath(par ts[2])
102 if err := addr.Project.Validate(); err != nil { 98 if err := addr.Project.Validate(); err != nil {
103 » » return nil, errors.Annotate(err).Reason("invalid project name: % (project)q"). 99 » » return nil, errors.Annotate(err, "invalid project name: %q", add r.Project).Err()
104 » » » D("project", addr.Project).
105 » » » Err()
106 } 100 }
107 101
108 if err := addr.Path.Validate(); err != nil { 102 if err := addr.Path.Validate(); err != nil {
109 » » return nil, errors.Annotate(err).Reason("invalid stream path: %( path)q"). 103 » » return nil, errors.Annotate(err, "invalid stream path: %q", addr .Path).Err()
110 » » » D("path", addr.Path).
111 » » » Err()
112 } 104 }
113 105
114 return &addr, nil 106 return &addr, nil
115 } 107 }
OLDNEW
« no previous file with comments | « logdog/common/storage/entry.go ('k') | logdog/server/archivist/archivist.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698