Skip to content

Commit dbca9c9

Browse files
committed
build: use @slack/logger for debugging parsechunks
1 parent 81140cc commit dbca9c9

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

packages/types/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
"bugs": {
2828
"url": "https://github.com/slackapi/node-slack-sdk/issues"
2929
},
30+
"dependencies": {
31+
"@slack/logger": "^4.0.0"
32+
},
3033
"scripts": {
3134
"prepare": "npm run build",
3235
"build": "npm run build:clean && tsc",

packages/types/src/chunk.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import { ConsoleLogger, LogLevel } from '@slack/logger';
2+
3+
const logger = new ConsoleLogger();
4+
logger.setLevel(LogLevel.DEBUG);
5+
16
/**
27
* Base interface for streaming message chunks.
38
* https://docs.slack.dev/messaging/sending-and-scheduling-messages#text-streaming
@@ -65,7 +70,7 @@ export function parseChunk(chunk: unknown): AnyChunk | null {
6570
const chunkObj = chunk as Record<string, unknown>;
6671

6772
if (!('type' in chunkObj) || typeof chunkObj.type !== 'string') {
68-
console.warn('Unknown chunk detected and skipped (missing type)', chunk);
73+
logger.debug('Unknown chunk detected and skipped (missing type)', chunk);
6974
return null;
7075
}
7176

@@ -75,15 +80,15 @@ export function parseChunk(chunk: unknown): AnyChunk | null {
7580
if (typeof chunkObj.text === 'string') {
7681
return chunkObj as unknown as MarkdownTextChunk;
7782
}
78-
console.warn('Invalid MarkdownTextChunk (missing text property)', chunk);
83+
logger.debug('Invalid MarkdownTextChunk (missing text property)', chunk);
7984
return null;
8085
}
8186

82-
if(type === 'plan_update') {
87+
if (type === 'plan_update') {
8388
if (typeof chunkObj.title === 'string') {
8489
return chunkObj as unknown as PlanUpdateChunk;
8590
}
86-
console.warn('Invalid PlanUpdateChunk (missing title property)', chunk);
91+
logger.debug('Invalid PlanUpdateChunk (missing title property)', chunk);
8792
return null;
8893
}
8994

@@ -97,10 +102,10 @@ export function parseChunk(chunk: unknown): AnyChunk | null {
97102
) {
98103
return chunkObj as unknown as TaskUpdateChunk;
99104
}
100-
console.warn('Invalid TaskUpdateChunk (missing required properties)', chunk);
105+
logger.debug('Invalid TaskUpdateChunk (missing required properties)', chunk);
101106
return null;
102107
}
103108

104-
console.warn(`Unknown chunk type detected and skipped: ${type}`, chunk);
109+
logger.debug(`Unknown chunk type detected and skipped: ${type}`, chunk);
105110
return null;
106111
}

0 commit comments

Comments
 (0)