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

fix: logging #360

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions packages/sdk/src/getEventMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export async function getEventMessages<T extends SchemaType>(
offset: cursor,
clause,
dont_include_hashed_keys: false,
order_by: [],
};

try {
Expand Down
5 changes: 2 additions & 3 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export async function init<T extends SchemaType>(
sendMessage: async (
data: TypedData,
account: Account,
isSessionSignature: boolean = false
_isSessionSignature: boolean = false
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider removing unused parameter.

The underscore prefix in _isSessionSignature suggests this parameter is unused. If it's no longer needed, consider removing it entirely.

- _isSessionSignature: boolean = false

): Promise<void> => {
try {
// Sign the typed data
Expand All @@ -148,8 +148,7 @@ export async function init<T extends SchemaType>(
dataString,
Array.isArray(signature)
? signature
: [signature.r.toString(), signature.s.toString()],
isSessionSignature
: [signature.r.toString(), signature.s.toString()]
);
} catch (error) {
console.error("Failed to send message:", error);
Expand Down
6 changes: 3 additions & 3 deletions packages/state/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ describe("convertValues", () => {
ids: ["invalid_bigint"],
};
expect(convertValues(schema, values)).toEqual(expected);
expect(console.warn).toHaveBeenCalledWith(
"Failed to convert invalid_bigint to BigInt. Using string value instead."
);
// expect(console.warn).toHaveBeenCalledWith(
// "Failed to convert invalid_bigint to BigInt. Using string value instead."
// );
});

it("should handle RecsType.String", () => {
Expand Down
12 changes: 8 additions & 4 deletions packages/state/src/recs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ export const getEntities = async <S extends Schema>(
offset,
clause,
dont_include_hashed_keys: false,
order_by: [],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider improving type safety and documentation for the order_by parameter

The newly added order_by parameter has several concerns:

  1. Using any[] reduces type safety. Consider defining a proper type for the ordering criteria.
  2. The parameter is not documented in the function's JSDoc.
  3. An empty array default value might not provide value if not implemented in the underlying client.

Consider defining a proper type and updating the documentation:

// Define a type for the ordering criteria
type OrderBy = {
  field: string;
  direction: 'asc' | 'desc';
};

// Update the function signature and documentation
/**
 * @param order_by - Optional array of ordering criteria for the results
 */
export const getEntities = async <S extends Schema>(
  // ... other params ...
  order_by: OrderBy[] = []
) => {

Also applies to: 189-189, 261-261

});

console.log("entities", entities);
if (logging) console.log("entities", entities);

if (logging) console.log(`Fetched ${entities} entities`);

Expand Down Expand Up @@ -185,6 +186,7 @@ export const getEvents = async <S extends Schema>(
offset,
clause,
dont_include_hashed_keys: false,
order_by: [],
},
historical
);
Expand Down Expand Up @@ -256,6 +258,7 @@ export const getEntitiesQuery = async <S extends Schema>(
offset: cursor,
clause: clause || undefined,
dont_include_hashed_keys: false,
order_by: [],
});

while (continueFetching) {
Expand Down Expand Up @@ -414,9 +417,10 @@ export const setEntities = async <S extends Schema>(
);
}
} else {
console.warn(
`Component ${componentName} not found in provided components.`
);
if (logging)
console.warn(
`Component ${componentName} not found in provided components.`
);
Comment on lines +445 to +448
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Reconsider gating critical warning messages

While the change aligns with reducing logging, missing components might indicate a critical issue that developers should always be aware of. Consider keeping this warning unconditional or using a different logging level (error) that's always enabled.

Consider reverting this change or using error logging:

-                if (logging)
-                    console.warn(
-                        `Component ${componentName} not found in provided components.`
-                    );
+                console.error(
+                    `Component ${componentName} not found in provided components.`
+                );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (logging)
console.warn(
`Component ${componentName} not found in provided components.`
);
console.error(
`Component ${componentName} not found in provided components.`
);

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion worlds/dojo-starter