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

Validate Date & throw error with better error message #56

Open
7 tasks
dance2die opened this issue Feb 2, 2019 · 0 comments
Open
7 tasks

Validate Date & throw error with better error message #56

dance2die opened this issue Feb 2, 2019 · 0 comments

Comments

@dance2die
Copy link
Owner

dance2die commented Feb 2, 2019

To Do

  • Add test cases for
    • getDates
    • getMatrix
  • Add guard clause throwIfDateIsInvalid
    • Message: "Invalid date was passed"
  • If date falls outside of min/max dates, throw an error throwIfDateIsOutOfRange
    • Message: "Date is out of range: It should be between x & x..."

Steps to reproduce

Pass bad date as an input to getDates or getMatrix.

const CalendarDates = require("calendar-dates");
const calendarDates = new CalendarDates();

const log = console.log;
// const may2018 = new Date(0,0,2);
const may2018 = 1;

mainAsync = async () => {
  const mayDates = await calendarDates.getDates(may2018);
  const mayMatrix = await calendarDates.getMatrix(may2018);
  // throw new Error('random error');
  log(`May, 2018 Dates`, mayDates);
  log(`May, 2018 Matrix`, mayMatrix);
};
mainAsync();
node v9.7.1 linux/amd64
   
(node:103) UnhandledPromiseRejectionWarning: TypeError: t.getMonth is not a function
    at getPreviousDates (/home/runner/node_modules/calendar-dates/dist/calendardates.cjs.js:1:1243)
    at /home/runner/node_modules/calendar-dates/dist/calendardates.cjs.js:1:663
    at new Promise (<anonymous>)
    at getDatesWithMetadata (/home/runner/node_modules/calendar-dates/dist/calendardates.cjs.js:1:628)
    at /home/runner/node_modules/calendar-dates/dist/calendardates.cjs.js:1:2193
    at new Promise (<anonymous>)
    at t.value (/home/runner/node_modules/calendar-dates/dist/calendardates.cjs.js:1:2160)
    at mainAsync (evalmachine.<anonymous>:9:40)
    at evalmachine.<anonymous>:15:1
    at Script.runInContext (vm.js:74:29)
(node:103) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:103) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
=> Promise { <pending> }

Try it here.
https://repl.it/@dance2die/calendar-date-edge-cases

Expected behavior

Report a better error message that the exception is thrown due to invalid date input.

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

1 participant