this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

lexgen: CAR output encoding; some segfault guards

+16 -8
+16 -8
lex/gen.go
··· 17 17 const ( 18 18 EncodingCBOR = "application/cbor" 19 19 EncodingJSON = "application/json" 20 + EncodingCAR = "application/vnd.ipld.car" 20 21 EncodingANY = "*/*" 21 22 ) 22 23 ··· 128 129 129 130 if ts.Output != nil { 130 131 if ts.Output.Schema == nil { 131 - if ts.Output.Encoding != "application/cbor" { 132 + if ts.Output.Encoding != "application/cbor" && ts.Output.Encoding != "application/vnd.ipld.car" { 132 133 panic(fmt.Sprintf("strange output type def in %s", s.ID)) 133 134 } 134 135 } else { ··· 219 220 r = s.ID + r 220 221 } 221 222 223 + if _, known := defmap[r]; known != true { 224 + panic(fmt.Sprintf("reference to unknown record type: %s", r)) 225 + } 222 226 defmap[r].Type.record = true 223 227 } 224 228 } ··· 269 273 270 274 if reqcode { 271 275 name := nameFromID(s.ID, prefix) 276 + if _, ok := s.Defs["main"]; !ok { 277 + return fmt.Errorf("schema %q doesn't have a main def", s.ID) 278 + } 272 279 if err := writeMethods(name, s.Defs["main"], buf); err != nil { 273 280 return err 274 281 } ··· 347 354 return ts.WriteRPC(w, typename) 348 355 case "procedure": 349 356 return ts.WriteRPC(w, typename) 350 - case "object": 357 + case "object", "string": 351 358 return nil 352 359 default: 353 360 return fmt.Errorf("unrecognized lexicon type %q", ts.Type) ··· 420 427 out := "error" 421 428 if s.Output != nil { 422 429 switch s.Output.Encoding { 423 - case EncodingCBOR: 430 + case EncodingCBOR, EncodingCAR: 424 431 out = "([]byte, error)" 425 432 case EncodingJSON: 426 433 out = fmt.Sprintf("(*%s_Output, error)", fname) ··· 436 443 outRet := "nil" 437 444 if s.Output != nil { 438 445 switch s.Output.Encoding { 439 - case EncodingCBOR: 446 + case EncodingCBOR, EncodingCAR: 440 447 fmt.Fprintf(w, "buf := new(bytes.Buffer)\n") 441 448 outvar = "buf" 442 449 errRet = "nil, err" 443 450 outRet = "buf.Bytes(), nil" 444 - 445 451 case EncodingJSON: 446 452 fmt.Fprintf(w, "\tvar out %s_Output\n", fname) 447 453 outvar = "&out" ··· 598 604 } 599 605 } 600 606 if pref == "" { 601 - return fmt.Errorf("no matching prefix for schema %q", s.ID) 607 + return fmt.Errorf("no matching prefix for schema %q (tried %s)", s.ID, prefixes) 602 608 } 603 609 604 610 ssets[pref] = append(ssets[pref], s) ··· 704 710 switch s.Output.Encoding { 705 711 case "application/json": 706 712 returndef = fmt.Sprintf("(*%s.%s_Output, error)", impname, shortname) 707 - case "application/cbor": 713 + case "application/cbor", "application/vnd.ipld.car": 708 714 returndef = fmt.Sprintf("(io.Reader, error)") 709 715 default: 710 716 return fmt.Errorf("unrecognized output encoding: %q", s.Output.Encoding) ··· 881 887 assign = "out, handleErr" 882 888 fmt.Fprintf(w, "var out *%s.%s\n", impname, tname+"_Output") 883 889 returndef = fmt.Sprintf("(*%s.%s_Output, error)", impname, tname) 884 - case "application/cbor": 890 + case "application/cbor", "application/vnd.ipld.car": 885 891 assign = "out, handleErr" 886 892 fmt.Fprintf(w, "var out io.Reader\n") 887 893 returndef = "(io.Reader, error)" ··· 902 908 fmt.Fprintf(w, "return c.Stream(200, \"application/octet-stream\", out)\n}\n\n") 903 909 case EncodingCBOR: 904 910 fmt.Fprintf(w, "return c.Stream(200, \"application/octet-stream\", out)\n}\n\n") 911 + case EncodingCAR: 912 + fmt.Fprintf(w, "return c.Stream(200, \"application/vnd.ipld.car\", out)\n}\n\n") 905 913 default: 906 914 return fmt.Errorf("unrecognized output encoding: %s", s.Output.Encoding) 907 915 }