Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

fix: error on reusing some of the reports #101

Merged
merged 3 commits into from
Dec 13, 2017
Merged

Conversation

Flackus
Copy link
Contributor

@Flackus Flackus commented Dec 12, 2017

Original problem and discussion: https://nda.ya.ru/3TjUi7

Commits are thoroughly described in theirs commit messages.

Alexey Rybakov added 3 commits December 12, 2017 19:51
* Custom Error class should be an Error inheritor
* Initializing app from server should be checked for exceptions
* Move from `node-targz` to an own version without `nextTick` (https://github.com/lafin/node-targz/blob/master/lib/index.js#L12)
`Array.prototype.find` in clean environment:
```
function find() { [native code] }
```

With dependencies and imports from `app.js`:
```
function (value, equals) {
    equals = equals || this.contentEquals || Object.equals;
    for (var index = 0; index < this.length; index++) {
        if (index in this && equals(this[index], value)) {
            return index;
        }
    }
    return -1;
}
```
throw new ReuseError(`Nothing to reuse in ${report}`, e);
}
},
(e) => {
Copy link
Member

Choose a reason for hiding this comment

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

а почему именно такая запись, а не через catch ниже?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Потому что это не равнозначный по поведению код.
Здесь два разных типа ошибки, которые нужно бросать.
Если ты напишешь catch ниже, то заодно схватишь ошибку Nothing to reuse in ....

Copy link
Contributor

Choose a reason for hiding this comment

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

я думаю жека имел ввиду catch выше

.pipe(zlib.createGunzip())
.on('error', reject)
.pipe(tar.extract(destination))
.on('error', reject)
Copy link
Member

Choose a reason for hiding this comment

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

достаточно ведь одной подписки на ошибки в самом конце. Если в каком-то из пайпов случится ошибка, то мы провалимся сразу в этот обработчик

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Нет, это не так.

reuse && reuse.result.metaInfo && JSON.parse(reuse.result.metaInfo)
);
let extraMeta = {};
if (reuse && reuse.result.metaInfo) {
Copy link
Member

Choose a reason for hiding this comment

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

_.has(reuse, 'result.metaInfo')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Вкусовщина в данном случае.

} catch (e) {}
}

const metaInfoObj = Object.assign({}, state.metaInfo, extraMeta);
Copy link
Member

Choose a reason for hiding this comment

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

Object.assign умеет мерджить только top-level:

Object.assign({}, {a: {b: 1}}, {a: {z: 2}}); // ==> {a: {z: 2}}

мы тут случайно не отгребем?

Copy link
Contributor Author

@Flackus Flackus Dec 13, 2017

Choose a reason for hiding this comment

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

Нет, не думаю.
@kvmamich?

Copy link
Contributor

@kvmamich kvmamich Dec 13, 2017

Choose a reason for hiding this comment

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

Когда metaInfo был JSON'ом, там был только один уровень
Теперь я вообще не знаю, что делать с этим кодом
Тут выполнялся мёрдж metaInfo из стейта и из реиспользуемого отчёта, но с тех пор, как в отчёте появился html...

Copy link
Member

Choose a reason for hiding this comment

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

ну сейчас по коду мы просто не будем экстендить мету. Но мне кажется, что при реюзе пользователям вообще не нужна мета - они просто будут обновлять скрины

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Давайте вообще этот код уберем тогда? В нём как-то не осталось смысла.

Copy link
Member

Choose a reason for hiding this comment

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

не, тут оставляем. Я заведу задачу про то, чтобы мету делать кликабельной уже на клиенте. И сюда будет приезжать валидный объект.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ок. Какие еще вопросы по этому PR?

Copy link
Member

Choose a reason for hiding this comment

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

только про пайпы, но я про это отдельно почитаю ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ну а что там читать:

'use strict';

const path = require('path');
const os = require('os');
const homedir = os.homedir();
const decompress = require('./lib/utils').decompress;

return decompress(path.resolve(homedir, 'defunct.file'), path.resolve(homedir, 'test.txt'))
    .then(() => console.log('success'))
    .catch(e => console.error('error'));
$ node test.js
error

Убираем строку номер 13 в lib/utils.js:

$ node test.js
events.js:182
      throw er; // Unhandled 'error' event
      ^

Error: ENOENT: no such file or directory, open '/Users/flack/defunct.file'

Copy link
Member

Choose a reason for hiding this comment

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

да не, я говорил про

    .pipe(zlib.createGunzip())
    .on('error', reject)

в общем, забей :)

it('should be an Error inheritor', () => {
const error = new ExtendableError('msg');

assert.isTrue(error instanceof Error);
Copy link
Member

Choose a reason for hiding this comment

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

assert.instanceOf(new ExtendableError('msg'), Error);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Хуже читается, кмк, но не принципиально.

// tempDir at this moment contains only report archive and unpacked report in some directory
.then(() => {
const reportDirName = fs.readdirSync(tempDir)
.find((f) => fs.statSync(path.resolve(tempDir, f)).isDirectory());
.filter((f) => fs.statSync(path.resolve(tempDir, f)).isDirectory())[0];
Copy link
Member

Choose a reason for hiding this comment

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

вот тут я не понял. почему мы первый элемент берем?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Потому что в директории две записи: gemini-report (директория) и свежескачанный тарник.
В оригинальном ревью @j0tunn говорил, что хардкодить имя директории отчета нельзя. Отсюда такое.
Первый мы берем, потому что это временная, нами созданная папка, там никаких других директорий быть не может.

@Flackus Flackus merged commit ff5b20d into master Dec 13, 2017
@Flackus Flackus deleted the fix/reports-reuse-meta branch December 13, 2017 13:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants