xeipuuv / gojsonschema

An implementation of JSON Schema, draft v4 v6 & v7 - Go language
2.55k stars 357 forks source link

Panic at pointer dereference. #188

Open jcoyne opened 6 years ago

jcoyne commented 6 years ago
runtime error: invalid memory address or nil pointer dereference
...
    sigpanic: panicmem()
/Users/jcoyne/golang/src/github.com/sul-dlss-labs/taco/vendor/github.com/xeipuuv/gojsonschema/result.go:151 (0x15fb940)
    (*DepositResourceValidator).ValidateResource: return len(v.errors) == 0
/Users/jcoyne/golang/src/github.com/sul-dlss-labs/taco/handlers/deposit_resource.go:33 (0x160f5a1)
johandorland commented 6 years ago

Do you have a snippet of code to reproduce this? v is probably nil, but it's hard to find the root cause of this issue just from a single stack trace.

jcoyne commented 6 years ago

@johandorland I'm afraid I don't. I since switched to using github.com/santhosh-tekuri/jsonschema, which seemed to be able to meet my needs.

I belive I was using this schema:

{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "title": "Deposit Resource",
  "description": "Create Request Domain Resource (Collection, Object, Fileset, or File or any subclass of those) Request Body. For TACO API high-level validation of incoming resources.",
  "type": "object",
  "required": ["@context", "@type", "label", "administrative", "access", "identification", "structural"],
  "not": {
    "required": ["version"]
  },
  "properties": {
    "@context": {
      "description": "URI for the JSON-LD context definitions.",
      "type": "string"
    },
    "@type": {
      "description": "The content type of the domain resource.",
      "type": "string",
      "enum": [
        "http://sdr.sul.stanford.edu/models/sdr3-collection.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-curated-collection.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-user-collection.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-exhibit.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-series.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-object.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-3d.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-agreement.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-book.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-document.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-geo.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-image.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-page.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-photograph.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-manuscript.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-map.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-media.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-track.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-webarchive-binary.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-webarchive-seed.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-file.jsonld",
        "http://sdr.sul.stanford.edu/models/sdr3-fileset.jsonld"
      ]
    },
    "label": {
      "description": "Primary processing label (can be same as title) for a resource.",
      "type": "string"
    },
    "access": {
      "description": "Access Metadata for the Resource.",
      "type": "object",
      "required": ["access", "download"],
      "properties": {
        "access": {
          "description": "Access level for the resource.",
          "type": "string",
          "enum": ["world", "stanford", "location-based", "citation-only", "dark"]
        },
        "download": {
          "description": "Download level for the resource metadata.",
          "type": "string",
          "enum": ["world", "stanford", "location-based", "citation-only", "dark"]
        }
      }
    },
    "administrative": {
      "type": "object",
      "description": "Administrative metadata for the SDR resource.",
      "required": ["sdrPreserve"],
      "properties": {
        "sdrPreserve": {
          "description": "If this resource should be sent to Preservation.",
          "type": "boolean"
        }
      }
    },
    "identification": {
      "type": "object",
      "description": "Identifying information for the resource.",
      "not": {
        "required": ["identifier"]
      }
    },
    "structural": {
      "description": "Structural metadata for the Resource.",
      "type": "object",
      "required": ["hasAgreement"],
      "properties": {
        "hasAgreement": {
          "description": "Agreement that covers the deposit of the resource into SDR.",
          "type": "string"
        }
      }
    }
  }
}