Skip to content

Commit

Permalink
Merge branch 'next' into fix-plugin-koa-request-body
Browse files Browse the repository at this point in the history
* next:
  Ensure we skip the correct number of frames
  Update ios vendoring script to match PLAT-5777 requirements
  Pin RN Navigation dependency versions
  • Loading branch information
djskinner committed Mar 12, 2021
2 parents ba4a6aa + fbade08 commit 1697852
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = (app, client) => {

const handler = (err, vm, info) => {
const handledState = { severity: 'error', unhandled: true, severityReason: { type: 'unhandledException' } }
const event = client.Event.create(err, true, handledState, 1)
const event = client.Event.create(err, true, handledState, 'vue error handler', 1)

event.addMetadata('vue', {
errorInfo: ErrorTypeStrings[info] || info,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/vue2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = (Vue, client) => {

const handler = (err, vm, info) => {
const handledState = { severity: 'error', unhandled: true, severityReason: { type: 'unhandledException' } }
const event = client.Event.create(err, true, handledState, 1)
const event = client.Event.create(err, true, handledState, 'vue error handler', 1)

event.addMetadata('vue', {
errorInfo: info,
Expand Down
66 changes: 66 additions & 0 deletions packages/plugin-vue/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('bugsnag vue', () => {
sendEvent: (payload) => {
expect(payload.events[0].errors[0].errorClass).toBe('Error')
expect(payload.events[0].errors[0].errorMessage).toBe('oops')
expect(payload.events[0].errors[0].stacktrace[0].file).toBe(__filename)
expect(payload.events[0]._metadata.vue).toBeDefined()
expect(payload.events[0]._metadata.vue.component).toBe('MyComponent')
expect(payload.events[0]._metadata.vue.errorInfo).toBe('render function')
Expand Down Expand Up @@ -131,6 +132,43 @@ describe('bugsnag vue', () => {
errorHandler(new Error('oops'), { $options: {} }, 1)
})

it('tolerates string "errors"', done => {
const mockVueApp: Vue3App = {
use: (plugin) => {
plugin.install(mockVueApp)
},
config: { errorHandler: undefined }
}

const client = new Client({ apiKey: 'API_KEYYY', plugins: [new BugsnagVuePlugin()] })

// eslint-disable-next-line
mockVueApp.use(client.getPlugin('vue')!)

client._setDelivery(client => ({
sendEvent: (payload) => {
expect(payload.events[0].errors[0].errorClass).toBe('Error')
expect(payload.events[0].errors[0].errorMessage).toBe('oops')

// ensure the top-most stack frame has an accurate file; it should be
// this test file as that is where the error string was created
expect(payload.events[0].errors[0].stacktrace[0].file).toBe(__filename)

expect(payload.events[0]._metadata.vue).toBeDefined()
expect(payload.events[0]._metadata.vue.component).toBe('MyComponent')
expect(payload.events[0]._metadata.vue.errorInfo).toBe('render function')
done()
},
sendSession: () => {}
}))

expect(typeof mockVueApp.config.errorHandler).toBe('function')

const errorHandler = mockVueApp.config.errorHandler as unknown as Vue3ErrorHandler

errorHandler('oops', { $options: { name: 'MyComponent' } }, 1)
})

//
// VUE 2
//
Expand All @@ -150,6 +188,7 @@ describe('bugsnag vue', () => {
sendEvent: (payload) => {
expect(payload.events[0].errors[0].errorClass).toBe('Error')
expect(payload.events[0].errors[0].errorMessage).toBe('oops')
expect(payload.events[0].errors[0].stacktrace[0].file).toBe(__filename)
expect(payload.events[0]._metadata.vue).toBeDefined()
done()
},
Expand Down Expand Up @@ -179,6 +218,33 @@ describe('bugsnag vue', () => {
errorHandler(new Error('oops'), { $root: true, $options: {} }, 'callback for watcher "fooBarBaz"')
})

it('supports string "errors"', done => {
const mockVue = { config: { errorHandler: undefined } }
const client = new Client({ apiKey: 'API_KEYYY', plugins: [new BugsnagVuePlugin(mockVue)] })

client._setDelivery(client => ({
sendEvent: (payload) => {
expect(payload.events[0].errors[0].errorClass).toBe('Error')
expect(payload.events[0].errors[0].errorMessage).toBe('oops')

// ensure the top-most stack frame has an accurate file; it should be
// this test file as that is where the error string was created
expect(payload.events[0].errors[0].stacktrace[0].file).toBe(__filename)

expect(payload.events[0]._metadata.vue).toBeDefined()
done()
},
sendSession: () => {}
}))

expect(typeof mockVue.config.errorHandler).toBe('function')

const errorHandler = mockVue.config.errorHandler as unknown as Vue2ErrorHandler

// @ts-ignore
errorHandler('oops', { $root: true, $options: {} }, 'callback for watcher "fooBarBaz"')
})

describe('global Vue', () => {
// Workaround typescript getting upset at messing around with global
// by taking a reference as 'any' and modifying that instead
Expand Down
168 changes: 144 additions & 24 deletions packages/react-native/update-ios.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,145 @@
#!/usr/bin/env bash
set -e

IOS_REPO_DIR=../../../bugsnag-cocoa
IOS_DST=ios/vendor/bugsnag-cocoa

echo "Clearing out ${IOS_DST}"
rm -rf $IOS_DST

mkdir $IOS_DST

echo "Copying vendor code from $IOS_REPO_DIR"
rsync --delete -al "$IOS_REPO_DIR/CHANGELOG.md" "$IOS_DST/CHANGELOG.md"
rsync --delete -al "$IOS_REPO_DIR/UPGRADING.md" "$IOS_DST/UPGRADING.md"
rsync --delete -al "$IOS_REPO_DIR/VERSION" "$IOS_DST/VERSION"
rsync --delete -al "$IOS_REPO_DIR/README.md" "$IOS_DST/README.md"
rsync --delete -al "$IOS_REPO_DIR/ORGANIZATION.md" "$IOS_DST/ORGANIZATION.md"
rsync --delete -al "$IOS_REPO_DIR/Bugsnag/" "$IOS_DST/Bugsnag/"
rsync --delete -al "$IOS_REPO_DIR/Framework/" "$IOS_DST/Framework/"
rsync --delete -al "$IOS_REPO_DIR/Bugsnag.xcodeproj/" "$IOS_DST/Bugsnag.xcodeproj/"
rsync --delete -al "$IOS_REPO_DIR/Bugsnag.podspec.json" "$IOS_DST/Bugsnag.podspec.json"

echo "Recording version"
rm -rf ./ios/.bugsnag-cocoa-version
echo $(cd $IOS_REPO_DIR && git rev-parse HEAD) >> ./ios/.bugsnag-cocoa-version

# ----------
# Setup Code
# ----------

set -euo pipefail

SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
SCRIPT_NAME="${0##*/}"
TEMP_DIR=

cleanup() {
if [ "$TEMP_DIR" != "" ]; then
rm -rf "$TEMP_DIR"
fi
}
trap cleanup EXIT

print_help() {
echo "Usage: $SCRIPT_NAME [options]"
echo
echo "Options:"
echo " --version <version> (example: $SCRIPT_NAME --version 6.7.0)"
echo " --local <path> (example: $SCRIPT_NAME --local ../../../bugsnag-cocoa)"
echo " --sha <version> (example: $SCRIPT_NAME --sha c8210a3)"
}

error_bad_opt(){
echo "$SCRIPT_NAME: invalid option '$1'";
echo
print_help
exit 1
}

error_missing_field(){
echo "$SCRIPT_NAME: $1 missing required field";
echo
print_help
exit 1
}

MODE=unset
GIT_TAG=
BUGSNAG_COCOA_REPO_DIR=

# BSD-friendly getopt-style supporting longopt
while [ $# -gt 0 ]; do
case $1 in
--) shift; break;;
-*) case $1 in
--version)
if [ $# -lt 2 ]; then error_missing_field $1; fi
MODE=version
GIT_TAG=v$2
shift;;
--local)
if [ $# -lt 2 ]; then error_missing_field $1; fi
MODE=local
BUGSNAG_COCOA_REPO_DIR="$2"
shift;;
--sha)
if [ $# -lt 2 ]; then error_missing_field $1; fi
MODE=sha;
GIT_TAG=$2;
shift;;
-*)
error_bad_opt $1;;
esac;;
*) error_bad_opt $1;;
esac
shift
done

# -----------
# Script Code
# -----------

revendor_from_dir() {
local dst_dir="$SCRIPT_DIR/ios/vendor/bugsnag-cocoa"
local src_dir="$1"
if [ ! -d "$src_dir" ]; then
echo "Source directory not found: $src_dir"
exit 1
fi
if [ ! -d "$src_dir/Bugsnag.xcodeproj" ]; then
echo "Source directory doesn't look like the bugsnag-cocoa repo: $src_dir"
exit 1
fi

src_dir="$(cd "$src_dir" && pwd)"

echo "Rebuilding vendor dir ${dst_dir}"
rm -rf "$dst_dir"
mkdir "$dst_dir"

echo "Copying vendor code from $src_dir"
rsync --delete -al "$src_dir/CHANGELOG.md" "$dst_dir/CHANGELOG.md"
rsync --delete -al "$src_dir/UPGRADING.md" "$dst_dir/UPGRADING.md"
rsync --delete -al "$src_dir/VERSION" "$dst_dir/VERSION"
rsync --delete -al "$src_dir/README.md" "$dst_dir/README.md"
rsync --delete -al "$src_dir/ORGANIZATION.md" "$dst_dir/ORGANIZATION.md"
rsync --delete -al "$src_dir/Bugsnag/" "$dst_dir/Bugsnag/"
rsync --delete -al "$src_dir/Framework/" "$dst_dir/Framework/"
rsync --delete -al "$src_dir/Bugsnag.xcodeproj/" "$dst_dir/Bugsnag.xcodeproj/"
rsync --delete -al "$src_dir/Bugsnag.podspec.json" "$dst_dir/Bugsnag.podspec.json"

echo "Recording version"
rm -rf "$SCRIPT_DIR/ios/.bugsnag-cocoa-version"
echo $(cd "$src_dir" && git rev-parse HEAD) >> "$SCRIPT_DIR/ios/.bugsnag-cocoa-version"
}

revendor_from_clean_repo() {
local tag=$1
echo "Checking out https://github.com/bugsnag/bugsnag-cocoa.git with tag $tag"
TEMP_DIR="$(mktemp -d)"
pushd "$TEMP_DIR" >/dev/null
git clone https://github.com/bugsnag/bugsnag-cocoa.git
cd bugsnag-cocoa
git checkout $tag || exit 1
popd >/dev/null
revendor_from_dir "$TEMP_DIR/bugsnag-cocoa"
}

case $MODE in
unset)
print_help
exit 1
;;
version)
revendor_from_clean_repo $GIT_TAG
;;
sha)
revendor_from_clean_repo $GIT_TAG
;;
local)
revendor_from_dir "$BUGSNAG_COCOA_REPO_DIR"
;;
*)
echo "BUG: Invalid MODE: $MODE"
exit 1
;;
esac

echo "Update complete!"
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
npm i @bugsnag/plugin-react-navigation@$BUGSNAG_VERSION --registry=$REGISTRY_URL

npm i @react-native-community/masked-view --registry=$REGISTRY_URL
npm i @react-navigation/native --registry=$REGISTRY_URL
npm i @react-navigation/stack --registry=$REGISTRY_URL
npm i react-native-gesture-handler --registry=$REGISTRY_URL
npm i react-native-reanimated --registry=$REGISTRY_URL
npm i react-native-safe-area-context --registry=$REGISTRY_URL
npm i react-native-screens --registry=$REGISTRY_URL
npm i @react-native-community/masked-view@^0.1 --registry=$REGISTRY_URL
npm i @react-navigation/native@^5.9 --registry=$REGISTRY_URL
npm i @react-navigation/stack@^5.14 --registry=$REGISTRY_URL
npm i react-native-gesture-handler@^1.10 --registry=$REGISTRY_URL
npm i react-native-reanimated@^1.13 --registry=$REGISTRY_URL
npm i react-native-safe-area-context@^3.1 --registry=$REGISTRY_URL
npm i react-native-screens@^2.18 --registry=$REGISTRY_URL

0 comments on commit 1697852

Please sign in to comment.