{"id":18552483,"url":"https://github.com/andrejewski/professor-chaos","last_synced_at":"2025-05-15T11:13:05.531Z","repository":{"id":36909034,"uuid":"41216065","full_name":"andrejewski/professor-chaos","owner":"andrejewski","description":"Create non-life-threatening chaos in your programs","archived":false,"fork":false,"pushed_at":"2015-08-22T21:28:52.000Z","size":172,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T01:36:17.776Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Voytovych/java-basic-repository-001","license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrejewski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-22T16:38:47.000Z","updated_at":"2019-12-03T15:19:17.000Z","dependencies_parsed_at":"2022-09-08T07:52:40.271Z","dependency_job_id":null,"html_url":"https://github.com/andrejewski/professor-chaos","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fprofessor-chaos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fprofessor-chaos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fprofessor-chaos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Fprofessor-chaos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrejewski","download_url":"https://codeload.github.com/andrejewski/professor-chaos/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328389,"owners_count":22052633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T21:14:20.722Z","updated_at":"2025-05-15T11:13:03.898Z","avatar_url":"https://github.com/andrejewski.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n![Professor Chaos](https://raw.githubusercontent.com/andrejewski/professor-chaos/master/professor.jpg)\n\n# Professor Chaos\n\nProfessor Chaos is a tool to help unexpectently break your programs to see how they handle errors.\n\n```sh\nnpm install professor-chaos\n```\n\n## Usage\n\nProfessor Chaos has two methods of destruction: **time** and **call** based error triggers.\nThese errors are instances of `ChaosError` as to be more easily identifiable.\n\n```js\nvar pc = require('professor-chaos');\n\n/*\n  Calling `timer` will set an error to be thrown within a given timeframe.\n*/\nvar clock = pc.timer(1000);\n\n/*\n  Calling `fault` creates a break point where an error will be thrown/handled\n  within a random number of `hasError` calls between a given interval.\n*/\nvar fault = pc.fault(10);\n\nfunction handler(value1, value2, callback) {\n  if(fault.hasError()) {\n    fault.error('Random handler error', callback);\n  } else {\n    // do something\n  }\n}\n\n```\n\n## Methods\n\n### timer\n\n```js\n/*\ntimer(max: number): number\ntimer(min: number, max: number): number\n*/\n```\n\nAccepts a required maximum time `max` to wait to throw an error.\nAccepts an optional minimum time `min` to wait to throw an error which defaults to zero.\nReturns the `setTimeout` ID to allow you to use `clearTimeout` if necessary.\n\nThis function will asynchronously throw an error some time between `min` and `max`.\n\n### fault\n\n```js\n/*\nfault(max: number): Fault\nfault(min: number, max: number): Fault\n*/\n```\n\nAccepts a required maximum `max` to count to until throwing an error.\nAccepts an optional minimum `min` to count to until throwing an error which defaults to zero.\nReturns a `Fault` object.\n\nThis method creates a `Fault` object to be used inside the scope of a given function\n to create an error to then either throw or pass to a provided callback.\n\n```js\n/*\ninterface Fault {\n  hasError(): boolean\n  error(): void\n  error(message: string): void\n  error(callback: (error) =\u003e any): void\n  error(message: string, callback: (error) =\u003e any): void\n}\n*/\n```\n\nThe `hasError()` method returns whether or not an error if ready to be thrown.\nThe `hasError()` method is managed internally to see how often it is called\n and will signal `error()` to throw somewhere within the given `min` and `max` parameters.\n\nThe `error()` method accepts an optional error message which by default is awesome.\nThe `error()` method accepts an optional callback function which receives the\n error that would otherwise be thrown if no callback is provided.\n\nNote: `error()` will continue to create random errors after the first and each\n will be just as unpredictable as the last.\n\n## Contributing\n\nWe can always have more tests: if you find a bug, create an issue or be **fabulous**\nand fix the problem and write the tests up yourself in a coherent pull request.\n\nRun tests with the `npm test` command.\n\nFollow me on [Twitter](http://chrisandrejewski.com/twitter) for updates or just for the lolz\nand please check out my other [repositories](https://github.com/andrejewski) if I have earned it.\nI thank you for reading.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Fprofessor-chaos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrejewski%2Fprofessor-chaos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Fprofessor-chaos/lists"}