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

catch error on main funciton. #989

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/@dcl/sdk-commands/src/logic/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,16 @@ for (const path in compositeFromLoader) {

if ((entrypoint as any).main !== undefined) {
function _INTERNAL_startup_system() {
const maybePromise = (entrypoint as any).main()
if (maybePromise && typeof maybePromise === 'object' && typeof (maybePromise as unknown as Promise<unknown>).then === 'function') {
maybePromise.catch(console.error)
try {
const maybePromise = (entrypoint as any).main()
if (maybePromise && typeof maybePromise === 'object' && typeof (maybePromise as unknown as Promise<unknown>).then === 'function') {
maybePromise.catch(console.error)
}
} catch (e) {
console.error(e)
} finally {
engine.removeSystem(_INTERNAL_startup_system)
}
engine.removeSystem(_INTERNAL_startup_system)
}
engine.addSystem(_INTERNAL_startup_system, Infinity)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@dcl/sdk/src/network/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function entityUtils(engine: IEngine, profile: IProfile) {
let componentsIdsMutable = [...componentIds]
// Profile not initialized
if (!profile?.networkId) {
throw new Error('Profile not initialized. Called syncEntity inside the main() function.')
throw new Error('Profile not initialized. Call syncEntity inside the main() function.')
}

// We use the networkId generated by the user address to identify this entity through the network
Expand Down
16 changes: 8 additions & 8 deletions packages/@dcl/sdk/src/players/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function definePlayerHelper(engine: IEngine) {
const AvatarBase = defineAvatarBase(engine)
const playerEntities = new Map<Entity, string>()

let onEnterSceneCb: ((player: GetPlayerDataRes) => void) | undefined = undefined
let onLeaveSceneCb: ((userId: string) => void) | undefined = undefined
const onEnterSceneCb: ((player: GetPlayerDataRes) => void)[] = []
const onLeaveSceneCb: ((userId: string) => void)[] = []

engine.addSystem(() => {
const players = Array.from(engine.getEntitiesWith(PlayerIdentityData, AvatarBase))
Expand All @@ -41,14 +41,14 @@ function definePlayerHelper(engine: IEngine) {
playerEntities.set(entity, identity.address)

// Call onEnter callback
if (onEnterSceneCb) {
onEnterSceneCb(getPlayer({ userId: identity.address })!)
if (onEnterSceneCb.length) {
onEnterSceneCb.forEach((cb) => cb(getPlayer({ userId: identity.address })!))
}

// Check for changes/remove callbacks
AvatarBase.onChange(entity, (value) => {
if (!value && onLeaveSceneCb && playerEntities.get(entity)) {
onLeaveSceneCb(playerEntities.get(entity)!)
if (!value && onLeaveSceneCb.length && playerEntities.get(entity)) {
onLeaveSceneCb.forEach((cb) => cb(playerEntities.get(entity)!))
playerEntities.delete(entity)
}
})
Expand All @@ -58,10 +58,10 @@ function definePlayerHelper(engine: IEngine) {

return {
onEnterScene(cb: (player: GetPlayerDataRes) => void) {
onEnterSceneCb = cb
onEnterSceneCb.push(cb)
},
onLeaveScene(cb: (userId: string) => void) {
onLeaveSceneCb = cb
onLeaveSceneCb.push(cb)
},
/**
* Returns the info of the player if it's in the scene.
Expand Down
Loading