peril: Getting 'TypeError: danger.git.JSONDiffForFile is not a function'

When running a dangerfile containing a call to danger.git.JSONDiffForFile() on peril the following error is thrown:

error: UnhandledRejection Error:  TypeError: danger.git.JSONDiffForFile is not a function
	at _callee$ (/app/danger-0.9n2i29890gp.js:62:54)
	at Object.apply (/app/node_modules/vm2/lib/contextify.js:87:36)
	at tryCatch (/app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:65:40)
	at Generator.invoke [as _invoke] (/app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:303:22)
	at tryCatch (/app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:65:40)
	at Generator.prototype.(anonymous function) [as next] (/app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:117:21)
	at invoke (/app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:155:20)
	at /app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:202:11
	at new Promise (<anonymous>)
	at callInvokeWithMethodAndArg (/app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:201:16)
/app/out/peril.js:25
throw reason;
^
TypeError: danger.git.JSONDiffForFile is not a function
	at _callee$ (/app/danger-0.9n2i29890gp.js:62:54)
	at Object.apply (/app/node_modules/vm2/lib/contextify.js:87:36)
	at tryCatch (/app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:65:40)
	at Generator.invoke [as _invoke] (/app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:303:22)
	at Generator.prototype.(anonymous function) [as next] (/app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:117:21)
	at tryCatch (/app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:65:40)
	at invoke (/app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:155:20)
	at /app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:202:11
	at new Promise (<anonymous>)
	at callInvokeWithMethodAndArg (/app/node_modules/babel-polyfill/node_modules/regenerator-runtime/runtime.js:201:16)

Here’s an example dangerfile that should trigger the error.

import { danger } from 'danger';

(async function () {
    const modifiedComposerFile = danger.git.modified_files.find(file => file === 'composer.json');
    if (modifiedComposerFile) {
        const composerDiff = await danger.git.JSONDiffForFile(modifiedComposerFile);
    }
})();

Running the same dangerfile locally using the danger pr command works without error. We use the current latest commit of master (9b835cba043e0a857faee8bdc81749046ff5532a). My local danger version is 3.8.8.

Is there any reason why JSONDiffForFile() would not be available in the object danger.git?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 26 (24 by maintainers)

Most upvoted comments

@roopakv All of the Peril settings I am using are in this repo: https://github.com/wordpress-mobile/peril-settings. I hope thats helpful!

No worries, those are the type definitions (think .h files) - which don’t really affect runtime behavior. I avoid classes in ES6, this is just confusing.

Somehow the function here isn’t getting called:

https://github.com/danger/danger-js/blob/56491b4d8b4adfb08a69dcc087b36f82a05939eb/source/platforms/git/gitJSONToGitDSL.ts#L50-L51

Can you verify if danger.github.utils.fileLinks exists inside a dangerfile?

I think it’s because this line in an even passes in the JSON DSL, not the full DSL (with functions etc) which would only happen if somehow Peril thinks it has an event

https://github.com/danger/peril/blob/master/api/source/runner/run.ts#L85