Skip to content

Commit

Permalink
chore: attach output to ffmpeg errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-orion committed Nov 13, 2023
1 parent a03e996 commit 0f224f4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {Touchable} from '@components/Touchable';
import {COLORS} from '@constants/colors';
import {openLink} from '@utils/device';
import React, {useCallback} from 'react';
import {Image} from 'react-native';
import {ImageSourcePropType, StyleSheet} from 'react-native';
import {Image, ImageSourcePropType, StyleSheet} from 'react-native';
import {rem} from 'rn-units';

interface Props {
Expand Down
7 changes: 4 additions & 3 deletions src/services/logging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ export function LoggingWrapper(app: React.ComponentType) {
return Sentry.wrap(app);
}

export function logError(error: unknown) {
export function logError(error: unknown, extra: Record<string, unknown> = {}) {
if (__DEV__) {
console.error(
'logError',
getErrorMessage(error),
error,
'\n\nstack:',
checkProp(error, 'stack') && error.stack,
extra,
);
} else {
const user = userSelector(store.getState());
Expand All @@ -72,10 +73,10 @@ export function logError(error: unknown) {
error,
isApiError(error)
? {
extra: {responseData: error.response?.data},
extra: {responseData: error.response?.data, ...extra},
tags: {api: error.response?.status},
}
: undefined,
: {extra},
);
});
}
Expand Down
14 changes: 8 additions & 6 deletions src/utils/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function extractFramesWithFFmpeg({
outputSize: number;
cropStartY: number;
}): Promise<string[]> {
let output;
try {
const outputUri = `${cacheDirectory}/${getFilenameFromPathWithoutExtension(
inputUri,
Expand All @@ -56,7 +57,7 @@ export async function extractFramesWithFFmpeg({
if (!returnCode?.isValueSuccess()) {
throw new Error(`Failed to execute FFmpeg command: ${command}`);
}
const output = await session.getOutput();
output = await session.getOutput();
const numberOfFrames = parseInt(
output
.match(/frame=(.*?)(\d+)/g)
Expand All @@ -75,16 +76,17 @@ export async function extractFramesWithFFmpeg({
inputUri,
)}_${(i + 1).toString().padStart(3, '0')}.jpg`,
);
} catch (e) {
logError(e);
throw e;
} catch (error) {
logError(error, {output});
throw error;
}
}

export async function getVideoDimensionsWithFFmpeg(videoUri: string) {
let output;
try {
const session = await FFmpegKit.execute(`-i ${videoUri}`);
const output = await session.getOutput();
output = await session.getOutput();

// Use regex to extract video dimensions from FFmpeg output
const regex = /, (\d+)x(\d+),/;
Expand All @@ -98,7 +100,7 @@ export async function getVideoDimensionsWithFFmpeg(videoUri: string) {
throw new Error('Failed to extract video dimensions.');
}
} catch (error) {
logError(error);
logError(error, {output});
throw error;
}
}

0 comments on commit 0f224f4

Please sign in to comment.