{"record":{"id":"be75d853ee70d254","repo":"DrKLO/Telegram","slug":"failed-to-create-the-encoder-s-n","errorCode":null,"errorMessage":"Failed to create the encoder: %s\\n","messagePattern":"Failed to create the encoder: (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/opus/celt/opus_custom_demo.c","lineNumber":107,"sourceCode":"   fin = fopen(inFile, \"rb\");\n   if (!fin)\n   {\n      fprintf (stderr, \"Could not open input file %s\\n\", argv[argc-2]);\n      return 1;\n   }\n   outFile = argv[argc-1];\n   fout = fopen(outFile, \"wb+\");\n   if (!fout)\n   {\n      fprintf (stderr, \"Could not open output file %s\\n\", argv[argc-1]);\n      fclose(fin);\n      return 1;\n   }\n\n   enc = opus_custom_encoder_create(mode, channels, &err);\n   if (err != 0)\n   {\n      fprintf(stderr, \"Failed to create the encoder: %s\\n\", opus_strerror(err));\n      fclose(fin);\n      fclose(fout);\n      return 1;\n   }\n   dec = opus_custom_decoder_create(mode, channels, &err);\n   if (err != 0)\n   {\n      fprintf(stderr, \"Failed to create the decoder: %s\\n\", opus_strerror(err));\n      fclose(fin);\n      fclose(fout);\n      return 1;\n   }\n   opus_custom_decoder_ctl(dec, OPUS_GET_LOOKAHEAD(&skip));\n\n   if (argc>7)\n   {\n      complexity=atoi(argv[5]);\n      opus_custom_encoder_ctl(enc,OPUS_SET_COMPLEXITY(complexity));","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/opus/celt/opus_custom_demo.c#L89-L125","documentation":"opus_custom_encoder_create(mode, channels, &err) set err to a non-zero error code. The mode was created successfully but the encoder object for the given channel count could not be built. The message prints opus_strerror(err) for the detail. Both open files are closed before returning.","triggerScenarios":"err != OPUS_OK. Typically OPUS_BAD_ARG when channels is not 1 or 2, or when the mode is inconsistent with the requested channels; or an allocation failure inside the encoder. channels comes from atoi(argv[2]) and is unchecked.","commonSituations":"Passing channels=0 or a value >2; passing a channel count the custom mode wasn't designed for; memory pressure during encoder allocation; a mode created with parameters incompatible with mono/stereo.","solutions":["Validate channels is 1 or 2 before creating the encoder.","Read the printed opus_strerror to identify OPUS_BAD_ARG vs allocation failure.","Match channels to the mode's design; if the mode expects mono, pass 1.","Free memory / reduce concurrent allocations if it's an allocation failure."],"exampleFix":"// before\nchannels = atoi(argv[2]); // user passes 0 or 3\nenc = opus_custom_encoder_create(mode, channels, &err);\n\n// after\nchannels = atoi(argv[2]);\nif (channels != 1 && channels != 2) { fprintf(stderr, \"channels must be 1 or 2\\n\"); return 1; }\nenc = opus_custom_encoder_create(mode, channels, &err);","handlingStrategy":"validation","validationCode":"// Validate channels before creating the encoder.\nchannels = atoi(argv[2]);\nif (channels != 1 && channels != 2) { fprintf(stderr, \"channels must be 1 or 2\\n\"); return 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict channels to {1,2} before opus_custom_encoder_create.","Read opus_strerror(err) to distinguish OPUS_BAD_ARG from allocation failure.","Match channels to the mode's design."],"tags":["opus","encoder","bad-arg","channels","audio","c"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}