Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Cannot call method 'replace' of undefined #14

Open
rabidgremlin opened this issue Oct 27, 2014 · 2 comments
Open

Fatal error: Cannot call method 'replace' of undefined #14

rabidgremlin opened this issue Oct 27, 2014 · 2 comments

Comments

@rabidgremlin
Copy link

Hi there,

I get a

Fatal error: Cannot call method 'replace' of undefined

error when trying to validate a schema that references another schema file. Stacktrace is

C:\tmp\api>grunt --stack
Running "tv4:todo" (tv4) task
> pass | apidef/todo_example.json

>> tv4 validated 1 of 1 value

Running "tv4:todos" (tv4) task
> load + todo.json
Fatal error: Cannot call method 'replace' of undefined
TypeError: Cannot call method 'replace' of undefined
    at C:\tmp\api\node_modules\grunt-tv4\lib\loader.js:28:13
    at fs.js:207:20
    at Object.oncomplete (fs.js:107:15)

This only occurs when the .json files are in a different folder from my Gruntfile

My Gruntfile is as follows:

var formats = require('tv4-formats');

module.exports = function(grunt) {

  grunt.loadNpmTasks('grunt-tv4');

  grunt.initConfig({
    tv4:{
        todo:{
                options: {            
                    root:grunt.file.readJSON('apidef/todo.json'),
                    formats:formats,
                },              
                src: ['apidef/todo_example.json']
        },
        todos:{
                options: {            
                    root:grunt.file.readJSON('apidef/todos.json'),
                    formats:formats,
                },              
                src: ['apidef/todos_example.json']
        },
    }   
  });

  grunt.registerTask('default', ['tv4']);
};

and my todos.json file is as follows:

{   
    "id":"todos",
    "type":"array",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "items": { "$ref": "todo.json"}            
}

Any ideas what I'm doing wrong?

@Bartvds
Copy link
Collaborator

Bartvds commented Oct 28, 2014

I don't see anything glaringly wrong in your config.

When I check the code at that stack-trace (https://github.com/Bartvds/grunt-tv4/blob/master/lib/loader.js#L28) then I think for some odd reason the loader has some bug and passes undefined instead of the file contents.

I'm at the office right now, so I'll have to look into it when I'm back from work.

@rabidgremlin
Copy link
Author

The full set of code can be found here
https://github.com/rabidgremlin/RAML-Experiments
On 28 Oct 2014 23:29, "Bart van der Schoor" notifications@github.com
wrote:

I don't see anything glaringly wrong in your config.

When I check the code at that stack-trace (
https://github.com/Bartvds/grunt-tv4/blob/master/lib/loader.js#L28) then
I think for some odd reason the loader has some bug and passes undefined
instead of the file contents.

I'm at the office right now, so I'll have to look into it when I'm back
from work.


Reply to this email directly or view it on GitHub
#14 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants