fix: fix Typescript types #5

Open
suyashtnt wants to merge 7 commits from fix/types into master
Collaborator
No description provided.
@ -38,2 +38,2 @@
if (!doLogging) {
console.warn("WARN: No logging channel! No logs of any kind will be sent to slack!")
// this is used instead of doLogging so typescript can coerce loggingChannel into just a string
if (!loggingChannel) {
Owner

uncertain why this is needed- since the channel is only ever used after checking doLogging

uncertain why this is needed- since the channel is only ever used after checking doLogging
Author
Collaborator

It is not. I will fix it

It is not. I will fix it
suyashtnt marked this conversation as resolved
@ -53,3 +58,2 @@
const goalDate = new Date(!!process.env.DATE? process.env.DATE : "3027/01/01");
if (Number.isNaN(goalDate.getDate())) throw new Error("DATE must be a valid date (e.g. yyyy/mm/dd)")
const goalDate = new Date(process.env.DATE ? process.env.DATE : "3027/01/01");
Owner

I'd prefer this left as !!, to be explicit

I'd prefer this left as !!, to be explicit
Author
Collaborator

Will add it

Will add it
suyashtnt marked this conversation as resolved
@ -140,0 +155,4 @@
* @param {Error} error the error object
*/
async function publishError(error) {
console.error("ERROR: ", error);
Owner

Does this log more than the error message? if so- changed functionality, if not- I'd prefer to explicitly know this is logging the message

Does this log more than the error message? if so- changed functionality, if not- I'd prefer to explicitly know this is logging the message
Author
Collaborator

I believe it does. I'll make this error.message then.

I believe it does. I'll make this `error.message` then.
suyashtnt marked this conversation as resolved
@ -140,0 +156,4 @@
*/
async function publishError(error) {
console.error("ERROR: ", error);
if (error) console.error(error);
Owner

redundant check now? also removed an !!

redundant check now? also removed an !!
Author
Collaborator

Oops

Oops
suyashtnt marked this conversation as resolved
@ -140,0 +160,4 @@
if (doLogging)
await publishMessage(
loggingChannel,
`ERROR: ${error.message}. Stack: ${error.stack}`,
Owner

Change in functionality- the stack isn't supposed to be sent to slack

Change in functionality- the stack isn't supposed to be sent to slack
Author
Collaborator

Will remove

Will remove
suyashtnt marked this conversation as resolved
@ -198,0 +242,4 @@
new Error(
`Tried to post a duplicate '${emoji}' reaction to message ${ts} in ${channelId}`,
),
);
Owner

this is why publishError never required an error object to be sent- this really shouldn't be treated like an error with a stack.

this is why publishError never required an error object to be sent- this really shouldn't be treated like an error with a stack.
Author
Collaborator

If it's not an error, then it shouldn't be published as one. Either

  • Handle it some other way
  • Let it be an actual error. Errors are errors.
If it's not an error, then it shouldn't be published as one. Either - Handle it some other way - Let it be an actual error. Errors are errors.
@ -298,0 +372,4 @@
// this _should_ always pass, but the type checker doesn't know that
if (error instanceof Error) {
publishError(error);
}
Owner

Why ignore logging an error here if it isn't one by some chance? You do elsewhere

Why ignore logging an error here if it isn't one by some chance? You do elsewhere
Author
Collaborator

Oops. Didn't realise there could be a sql error

Oops. Didn't realise there could be a sql error
suyashtnt marked this conversation as resolved
@ -352,1 +434,3 @@
publishError(String(error), error);
if (error instanceof Error) {
publishError(error);
}
Owner

Ditto of above

Ditto of above
suyashtnt marked this conversation as resolved
@ -370,1 +454,3 @@
publishError(String(error), error);
if (error instanceof Error) {
publishError(error);
}
Owner

Ditto

Ditto
suyashtnt marked this conversation as resolved
@ -499,1 +596,3 @@
publishError(String(error), error);
if (error instanceof Error) {
publishError(error);
}
Owner

Ditto

Ditto
suyashtnt marked this conversation as resolved
@ -32,3 +32,4 @@
const start =
regularStartQuotes[Math.floor(Math.random() * regularStartQuotes.length)];
/** @type {string | undefined} */
Owner

type is always a string here, never undefined, you literally typehint a similar case as only strings on L260 of app.js

type is always a string here, never undefined, you literally typehint a similar case as only strings on L260 of app.js
suyashtnt marked this conversation as resolved
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin fix/types:fix/types
git switch fix/types
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: firepup650/million-stats#5
No description provided.