@@ -12,9 +12,7 @@ import (
12
12
"encoding/pem"
13
13
"errors"
14
14
"fmt"
15
- "log"
16
15
"net/url"
17
- "os"
18
16
"regexp"
19
17
"strings"
20
18
"time"
78
76
schemaLoaderV12019 = gojsonschema .NewStringLoader (schemaV12019 ) //nolint:gochecknoglobals
79
77
)
80
78
81
- var logger = log .New (os .Stderr , " [did-go/did/doc] " , log .Ldate | log .Ltime | log .LUTC )
82
-
83
79
// ErrDIDDocumentNotExist error did doc not exist.
84
80
var ErrDIDDocumentNotExist = errors .New ("did document not exists" )
85
81
@@ -290,6 +286,7 @@ type Doc struct {
290
286
Updated * time.Time
291
287
Proof []Proof
292
288
processingMeta processingMeta
289
+ warnings []error
293
290
}
294
291
295
292
// processingMeta include info how to process the doc.
@@ -1221,7 +1218,7 @@ func (doc *Doc) JSONBytes() ([]byte, error) {
1221
1218
Context : doc .Context , ID : doc .ID , AlsoKnownAs : aka , VerificationMethod : vm ,
1222
1219
Authentication : auths , AssertionMethod : assertionMethods , CapabilityDelegation : capabilityDelegations ,
1223
1220
CapabilityInvocation : capabilityInvocations , KeyAgreement : keyAgreements ,
1224
- Service : populateRawServices ( doc .Service , doc . ID , doc . processingMeta . baseURI ), Created : doc .Created ,
1221
+ Service : doc .populateRawServices ( ), Created : doc .Created ,
1225
1222
Proof : populateRawProofs (context , doc .ID , doc .processingMeta .baseURI , doc .Proof ), Updated : doc .Updated ,
1226
1223
}
1227
1224
@@ -1347,6 +1344,12 @@ func (doc *Doc) VerificationMethods(customVerificationRelationships ...Verificat
1347
1344
return verificationMethods
1348
1345
}
1349
1346
1347
+ // Warning returns warnings in format of error suitable for use with methods such as errors.Is or errors.As
1348
+ // returns nil if there were no warnings.
1349
+ func (doc * Doc ) Warning () error {
1350
+ return errors .Join (doc .warnings ... )
1351
+ }
1352
+
1350
1353
// ErrProofNotFound is returned when proof is not found.
1351
1354
var ErrProofNotFound = errors .New ("proof not found" )
1352
1355
@@ -1373,7 +1376,13 @@ func (r *didKeyResolver) Resolve(id string) (*api.PublicKey, error) {
1373
1376
var ErrKeyNotFound = errors .New ("key not found" )
1374
1377
1375
1378
// nolint:funlen,gocognit,gocyclo,nestif
1376
- func populateRawServices (services []Service , didID , baseURI string ) []map [string ]interface {} {
1379
+ func (doc * Doc ) populateRawServices () []map [string ]interface {} {
1380
+ var (
1381
+ services = doc .Service
1382
+ didID = doc .ID
1383
+ baseURI = doc .processingMeta .baseURI
1384
+ )
1385
+
1377
1386
var rawServices []map [string ]interface {}
1378
1387
1379
1388
for i := range services {
@@ -1412,12 +1421,14 @@ func populateRawServices(services []Service, didID, baseURI string) []map[string
1412
1421
1413
1422
sepAccept , err := services [i ].ServiceEndpoint .Accept ()
1414
1423
if err != nil {
1415
- logger .Printf ("accept field of DIDComm V2 endpoint missing or invalid, it will be ignored: %v" , err )
1424
+ doc .warnings = append (doc .warnings ,
1425
+ fmt .Errorf ("accept field of DIDComm V2 endpoint missing or invalid, it will be ignored: %w" , err ))
1416
1426
}
1417
1427
1418
1428
sepURI , err := services [i ].ServiceEndpoint .URI ()
1419
1429
if err != nil {
1420
- logger .Printf ("URI field of DIDComm V2 endpoint missing or invalid, it will be ignored: %v" , err )
1430
+ doc .warnings = append (doc .warnings ,
1431
+ fmt .Errorf ("URI field of DIDComm V2 endpoint missing or invalid, it will be ignored: %w" , err ))
1421
1432
}
1422
1433
1423
1434
if services [i ].ServiceEndpoint .Type () == endpoint .DIDCommV2 {
@@ -1460,7 +1471,7 @@ func populateRawServices(services []Service, didID, baseURI string) []map[string
1460
1471
} else {
1461
1472
bytes , err := services [i ].ServiceEndpoint .MarshalJSON ()
1462
1473
if err != nil {
1463
- logger . Print ( err . Error () )
1474
+ doc . warnings = append ( doc . warnings , err )
1464
1475
}
1465
1476
1466
1477
rawService [jsonldServicePoint ] = json .RawMessage (bytes )
0 commit comments