#Exit code 1 [SOLVED]

202 messages · Page 1 of 1 (latest)

severe trout
#

I have no information to give but the screenshot the process exists with code 1. Can't log anything, I even tried "process.on" logging and it doesnt even read it, within index.ts

I have only a screenshot. I tried TSX, node.js, ts-node and bun.

I tried --inspect arg to check why it happens, but nothing happens.

Any ideas?

jade carbonBOT
#
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
analog epoch
#

compile ur ts to js, then run it. By using tsc (typescript) and node

severe trout
#

i did

#

didnt work

analog epoch
#

gonna need a bit more then "didnt work", show ss's, what did you run? What happens? What's ur code

severe trout
#

i did show the screenshot

#

the code is just a discord bot

#

doesnt run

#

i console logged above the import

#

like the description says

#

i did a lot of tests

#

and nothing works

#

it works perfectly fine on windows

#

forgot to mention im on macos

analog epoch
#

that's also ts code, you don't really run ts

quasi relic
#

What's the content of ./Kuramisa file? I assume it's just creating a DiscordJS Client class

fickle anchor
severe trout
#

and i tried withput nodemon

severe trout
analog epoch
#

exporting ur client doens't look very good either

fickle anchor
#

Show your console doing node ./dist/index.js

severe trout
#

its not a code problem tho

#

because the code doesnt even get executed

fickle anchor
#

Why are you exporting from your index.ts? That is indeed a code problem

#

The only reason why you would do that is circular imports. Which are a problem

severe trout
#

alright

#

ill remove default export

#

but like i said

#

it works on windows and linux

fickle anchor
#

And does indeed cause node to silently exit from time to time

severe trout
#

alright

#

ill try

fickle anchor
severe trout
#

wait no

#

it wont cause circular imports

#

because im exporting an already initialized class

fickle anchor
#

No. Not if something imported from ./Kuramisa tries to import it

severe trout
#

so i want to access the initiated class everywhere

#

if i try export { kuramisa } same issue?

fickle anchor
#

Yes

#

Don‘t export at all from your index. The only files that could import that are ones imported from index. Causing circular imports

severe trout
#

so how do i make it so i can export kuramisa instance to access it from other files without causing circular imports

fickle anchor
severe trout
#

hm

#

can u show me an example if u dont mind

modest masonBOT
severe trout
#

no parameters

#

like for example sapphire js provides a exported instance container that can access the client and everything already initialized anywhere without passing client around in parameters how do they do it?

#

what if i create a hook called useClient() which returns the client instance?

#

will that avoid circular imports?

#

for example within kuramisa client ill create a static method called useClient

#

nvm

#

static cant access this context

fickle anchor
#

They Export the container from a file and then add properties to it from other files. All of those files import the container file

severe trout
#

alright that makes sense

#

but can i also do what i suggested?

#

import Kuramisa from "./Kuramisa";

const kuramisa = new Kuramisa();

kuramisa.login();

export const useClient = () => kuramisa;
#

will this work instead?

fickle anchor
#

Why though? It makes no sense to me. What kind of files are those that need to “get“ the client without already having access to it?

analog epoch
#

also you'll likely have a this.on(..., ...args) or something like that somewhere if you have an event handler, you can just pass ur client in there. Or just use the interaction(ect).client. If you're worried about types you can just make a


declare module "discord.js" {
    interface Client {
    }
}
severe trout
#

or upon creating certain classes when the bot is already initialized/ready

fickle anchor
#

That’s rather vague. Name one specific use case

severe trout
analog epoch
#

i mean that's literally what most people do, but you do you

fickle anchor
#

What would the command need your client for? Considering it‘ll get called from interactionCreate event which (as gwapes stated) has a .client property on the interaction

severe trout
analog epoch
#

by editing the client class... all that does would just make your types available if using interaction.client

severe trout
modest masonBOT
#

We highly recommend you extend the Client structure properly instead of just attaching custom properties like .commands to the regular discord.js Client instance.

analog epoch
#

last link

analog epoch
#

interaction.client is ur extended client

fickle anchor
#

You cast or augment the module type? Where?

severe trout
analog epoch
#

interaction.client is ur extended client, by doing the declare module thing it means that interaction.client will be shown to ts as ur extended client. Meaning you don't have to do:

(interaction.client as Kuramisa)

Every time

severe trout
#

wait so

#

maybe i misunderstood

#

interaction.client will hold all those valuse that i extended too?

analog epoch
#

djs basically puts the client everywhere

#

yes

fickle anchor
#

Yes

severe trout
#

Ohhhh

#

OHH

#

im sorry

#

my bad

analog epoch
#

message.client, reaction.client (?), interaction.client

severe trout
#

ohh

#

i really didnt know that

#

that saves so much headaches

analog epoch
#

I pass it within my event/command handlers because i want to

#

fr

fickle anchor
#

Neither does ts (know that). Which is why you need to tell it by casting or augmenting

analog epoch
#

but i didn't know about augmenting (declare module ...) for ages, which is why i passed it as a param, ...args, client

severe trout
#

Alright ill try doing that

#

and then

#

reach back

analog epoch
#

I also didn't know that circular imports would just cause node to "crash" entirely and not give an error so that's nice to know

severe trout
fickle anchor
#

Was a long day for me to find that issue

analog epoch
#

good job you found out 😂 educating all of us lol

analog epoch
severe trout
#

One more question

analog epoch
#

oui

severe trout
#

will this cause a circular import?

#

im importing just the class

#

not the created instance of th e class

analog epoch
#

Not too sure on that one. I believe if you don't start the client in that file it's fine

#

Like if you just define it there, then use it inside ur index.ts/js it's fine

#

As that's what I do and it's fine

#

I have a Classes/CustomClient/CustomClient.ts file and the import it into /index.ts and use it there

#

So that way i can use it as a type in other files by importing it from Classes/CustomClient/CustomClient.ts

severe trout
#

no i mean like

#

i wanna pass the client around

#

should i instead do import type?

#

cuz im not using the Kuramisa itself but the one that is being passed in a constructor

analog epoch
#

I'm not 100% on it but what i said should be fine

severe trout
#

No i agree with you but since qjuh mentioned circular importing now im paranoid lol

severe trout
#

Yes i understand but im using typescript

#

so i need to import types

analog epoch
#

Then you’ll follow what I said and what Qjuh just said

fickle anchor
severe trout
severe trout
#

Same problem

#

I tried on macos

#

im still running into the issue

analog epoch
#

I’m not too sure if there’s a way to debug circular imports but that’ll likely be the culprit

severe trout
#

i spent around 6-7 hours of recoding the framework

#

its not circular imports

#

cuz i installed a eslint plugin that detects it

#

and im not getting any errors

analog epoch
#

Try and reinstall node? What’s ur version?

#

You can node —inspect as well which’ll give you an inspect thingy

#

That’s two - iOS being fun

severe trout
#

i did do that too :< i did it from scratch matter of fact

#

and i tried --inspect too

analog epoch
#

Ah

#

What’s ur version

#

And what actually happens? Does it just never log anything? What command do you use to start again and then show the file you start it with

severe trout
#

22.14.0

severe trout
analog epoch
#

“Crashes” with an error? Or it just doesn’t do anything

#

And don’t use ts-node, you compile the ts and run the js. Always. Bun is known to be a little finicky when it comes to running stuff

#

I also suggest deleting ur entire dist and recompiling

severe trout
severe trout
severe trout
#

yes i did the en dbit

#

and i did other stuff u mentioned too

analog epoch
#

?

#

You didn’t show

severe trout
#

found it

#

i attached a debeugger

#

instaed of shitty --inspect

#

never threw an error

analog epoch
#

Can u show the file you run

#

And what you do to run the bot

severe trout
#

yep that fixed it

analog epoch
#

That’s all that’s there?

severe trout
#

in index.ts yes

analog epoch
#

And I’m guessing you then run dist/index.js

fickle anchor
#

That blindly ignores the exception and does process.exit(1)

severe trout
#

but sadly uncaught exception handler happens

#

when the bot initialized

#

but in the past i have tried manually doing "process.on" in the index file

#

it never went thru

analog epoch
severe trout
#

"but sadly uncaught exception handler happens when the bot initialized"

fickle anchor
severe trout
fickle anchor
#

UncaughtExceptions are meant to crash your bot. And even more importantly: shown to you what exception was thrown

severe trout
#

oh you said it

#

nvm,

severe trout
#

but i would like to keep unhandledRejection for now

#

so if i miss a rejecction i can fix it without the bot crashing

analog epoch
#

Or just remove it atm to find out what’s happening

#

And add breakpoint logs

#

Most of this is standard debugging which imo you should really already be doing

severe trout
#

and its working

#

and fixed something

#

I have checkes throughout the app where if a env var is missing it will throw an error but even removing uncaughtException handler didnt fix it

#

so i just did this

analog epoch
#

Great