LoginSignup
2
0

More than 1 year has passed since last update.

Twilio CLIでプロファイルの切り替えがエラーになる

Last updated at Posted at 2020-05-16

2023年5月1日を持ちまして、株式会社KDDIウェブコミュニケーションズのTwilioリセール事業が終了したため、本記事に記載されている内容は正確ではないことを予めご了承ください。

はじめに

Twilio CLIを使っていて、プロファイルの切替時エラーが出たのでメモ。

これ、意外と問題が複雑だというのを最後に追記しました。

エラーの詳細

プロファイルの切り替えコマンド実行時に以下のようなエラーが出た。

twilio profiles:use プロファイル名
 » twilio-cli encountered an unexpected error. To report this issue, execute the command with the "-l debug" flag, then copy the output to a new issue here: https://github.com/twilio/twilio-cli/issues

原因を探る

では、言われた通りにデバッグフラグを付けて実行

twilio profiles:use プロファイル名 -l debug
[DEBUG] Config File: /Users/katsumi/.twilio-cli/config.json
 » twilio-cli encountered an unexpected error. To report this issue, execute the command with the "-l debug" flag, then copy the output to a new issue here: https://github.com/twilio/twilio-cli/issues
[DEBUG] EEXIST: file already exists, mkdir '/Users/katsumi/.twilio-cli'
[DEBUG] Error: EEXIST: file already exists, mkdir '/Users/katsumi/.twilio-cli'
    at Object.mkdirSync (fs.js:729:3)
    at Config.save (/usr/local/Cellar/twilio/2.0.2/libexec/node_modules/@twilio/cli-core/src/services/config.js:183:8)
    at ProfilesUse.run (/usr/local/Cellar/twilio/2.0.2/libexec/src/commands/profiles/use.js:12:54)

CLIの環境ファイル.twilio-cliがすでにあるからいかんぜよみたいなメッセージ。
でもこれないと困るし。うーん。
一応、use.jsのソースを確認すると12行目はこんな感じ。

use.js(12)
    const configSavedMessage = await this.configFile.save(this.userConfig);

で、ここから呼ばれているconfig.js(こいつはtwilio-cli-coreに入っている)の183行目はこんな感じ。

config.js(183)
fs.mkdirSync(this.configDir, { recursive: true });

なるほど。調べると、このrecursiveオプションは、Node 10.12で実装されたオプションらしい。
Node.js v10.12.0からは再帰的にディレクトリを作成できる。

ということで、現在のNodeのバージョンを見てみたら、

node -v
v10.8.0

はい。すみませんでした。
ということで、Nodeのバージョンをv12.8.0に上げたら解決しました。

どのバージョンから発生したのかを調べる

しかし、いつからrecursiveオプションとか使い始めたんやということで、先程のconfig.jsを履歴を追ってみると、twilio-cli-corev5.1.0で修正されているようだ。
修正点はこちら

で、twilio-cli-corev5.1.0は、twilio-cliv2.0.2から取り込まれているので、結論からすれば、Twilio CLIを2.0.2にバージョンアップしたのが原因ですね。

まとめ

最初は環境が壊れたのかと思って、.twilio-cliをいじったり色々したけど、ちゃんとエラーを追うのって大切ですね。
いずれにしろ、ちゃんとソースが公開されているから便利ですね。

追記

Nodeのバージョンを上げると、たしかにプロファイルの切り替えはできるようになるんですけど、今度は通常のコマンドが以下のようにエラーになります。

twilio api:studio:v2:flows:list
 » Installing keytar ...
 » Secure credential storage failed to load.

Alternatively, twilio-cli can use credentials stored in environment variables:

# OPTION 1 (recommended)
TWILIO_ACCOUNT_SID = your Account SID from twil.io/console
TWILIO_API_KEY = an API Key created at twil.io/get-api-key
TWILIO_API_SECRET = the secret for the API Key

# OPTION 2
TWILIO_ACCOUNT_SID = your Account SID from twil.io/console
TWILIO_AUTH_TOKEN = your Auth Token from twil.io/console

Once these environment variables are set, a twilio-cli profile is not required to move forward with installation.

今度はkeytarに問題がありそう。
Nodeのバージョンをv10.8.0に戻すと直るので、バージョンの問題ですね。
ということで、プロファイルの切り替えをするときだけ、Nodeのバージョンを上げて、それ以外は戻すというなんとも面倒なことして対応しています。とほほ。


Twilio(トゥイリオ)とは

https://cloudapi.kddi-web.com
Twilioは音声通話、メッセージング(SMS/チャット)、ビデオなどの 様々なコミュニケーション手段をアプリケーションやビジネスへ容易に組み込むことのできるクラウドAPIサービスです。初期費用不要な従量課金制で、各種開発言語に対応しているため、多くのハッカソンイベントやスタートアップなどにも、ご利用いただいております。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0